Skip to content

Commit

Permalink
Merge pull request #193 maintenance: move maintenance task management…
Browse files Browse the repository at this point in the history
… to service

maintenance: move maintenance task management to service
  • Loading branch information
wilbaker authored Oct 29, 2019
2 parents 0991adf + 68a37b4 commit a388f0c
Show file tree
Hide file tree
Showing 29 changed files with 757 additions and 768 deletions.
120 changes: 0 additions & 120 deletions Scalar.Common/Maintenance/GitMaintenanceQueue.cs

This file was deleted.

91 changes: 0 additions & 91 deletions Scalar.Common/Maintenance/GitMaintenanceScheduler.cs

This file was deleted.

33 changes: 33 additions & 0 deletions Scalar.Common/Maintenance/MaintenanceTasks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;

namespace Scalar.Common.Maintenance
{
public static class MaintenanceTasks
{
public enum Task
{
Invalid = 0,
FetchCommitsAndTrees,
LooseObjects,
PackFiles,
CommitGraph,
}

public static string GetVerbTaskName(Task task)
{
switch (task)
{
case Task.FetchCommitsAndTrees:
return ScalarConstants.VerbParameters.Maintenance.FetchCommitsAndTreesTaskName;
case Task.LooseObjects:
return ScalarConstants.VerbParameters.Maintenance.LooseObjectsTaskName;
case Task.PackFiles:
return ScalarConstants.VerbParameters.Maintenance.PackFilesTaskName;
case Task.CommitGraph:
return ScalarConstants.VerbParameters.Maintenance.CommitGraphTaskName;
default:
throw new ArgumentException($"Invalid or unknown task {task.ToString()}", nameof(task));
}
}
}
}
12 changes: 12 additions & 0 deletions Scalar.Common/ScalarConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ public static class Unmount
{
public const string SkipLock = "skip-wait-for-lock";
}

public static class Maintenance
{
public const string Task = "task";

public const string FetchCommitsAndTreesTaskName = "fetch-commits-and-trees";
public const string LooseObjectsTaskName = "loose-objects";
public const string PackFilesTaskName = "pack-files";
public const string CommitGraphTaskName = "commit-graph";

public const string BatchSizeOptionName = "batch-size";
}
}

public static class UpgradeVerbMessages
Expand Down
15 changes: 1 addition & 14 deletions Scalar.Mount/InProcessMount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class InProcessMount

private ScalarEnlistment enlistment;
private ITracer tracer;
private GitMaintenanceScheduler maintenanceScheduler;

private CacheServerInfo cacheServer;
private RetryConfig retryConfig;
Expand Down Expand Up @@ -181,7 +180,7 @@ private T CreateOrReportAndExit<T>(Func<T> factory, string reportMessage)
}
}

private void HandleRequest(ITracer tracer, string request, NamedPipeServer.Connection connection)
private void HandleRequest(ITracer requestTracer, string request, NamedPipeServer.Connection connection)
{
NamedPipeMessages.Message message = NamedPipeMessages.Message.FromString(request);

Expand Down Expand Up @@ -258,7 +257,6 @@ private void HandleUnmountRequest(NamedPipeServer.Connection connection)
this.currentState = MountState.Unmounting;

connection.TrySendResponse(NamedPipeMessages.Unmount.Acknowledged);
this.UnmountAndStopWorkingDirectoryCallbacks();
connection.TrySendResponse(NamedPipeMessages.Unmount.Completed);

this.unmountEvent.Set();
Expand Down Expand Up @@ -286,8 +284,6 @@ private void MountAndStartWorkingDirectoryCallbacks(CacheServerInfo cache)
GitObjectsHttpRequestor objectRequestor = new GitObjectsHttpRequestor(this.context.Tracer, this.context.Enlistment, cache, this.retryConfig);
this.gitObjects = new ScalarGitObjects(this.context, objectRequestor);

this.maintenanceScheduler = this.CreateOrReportAndExit(() => new GitMaintenanceScheduler(this.context, this.gitObjects), "Failed to start maintenance scheduler");

int majorVersion;
int minorVersion;
if (!RepoMetadata.Instance.TryGetOnDiskLayoutVersion(out majorVersion, out minorVersion, out error))
Expand All @@ -303,14 +299,5 @@ private void MountAndStartWorkingDirectoryCallbacks(CacheServerInfo cache)
ScalarPlatform.Instance.DiskLayoutUpgrade.Version.CurrentMajorVersion);
}
}

private void UnmountAndStopWorkingDirectoryCallbacks()
{
if (this.maintenanceScheduler != null)
{
this.maintenanceScheduler.Dispose();
this.maintenanceScheduler = null;
}
}
}
}
7 changes: 7 additions & 0 deletions Scalar.Service/IRegisteredUserStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Scalar.Service
{
public interface IRegisteredUserStore
{
UserAndSession RegisteredUser { get; }
}
}
7 changes: 0 additions & 7 deletions Scalar.Service/IRepoMounter.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Scalar.Service/IRepoRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Scalar.Common.Maintenance;

namespace Scalar.Service
{
Expand All @@ -8,7 +9,7 @@ public interface IRepoRegistry
bool TryDeactivateRepo(string repoRoot, out string errorMessage);
bool TryGetActiveRepos(out List<RepoRegistration> repoList, out string errorMessage);
bool TryRemoveRepo(string repoRoot, out string errorMessage);
void AutoMountRepos(string userId, int sessionId);
void RunMaintenanceTaskForRepos(MaintenanceTasks.Task task, string userId, int sessionId);
void TraceStatus();
}
}
9 changes: 9 additions & 0 deletions Scalar.Service/IScalarVerbRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Scalar.Common.Maintenance;

namespace Scalar.Service
{
public interface IScalarVerbRunner
{
bool CallMaintenance(MaintenanceTasks.Task task, string repoRoot, int sessionId);
}
}
8 changes: 8 additions & 0 deletions Scalar.Service/IServiceTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Scalar.Service
{
public interface IServiceTask
{
void Execute();
void Stop();
}
}
Loading

0 comments on commit a388f0c

Please sign in to comment.