mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 22:17:51 +01:00
Scripts executed by deployment events should now respect Session:LowPriorityDeploymentProcesses
This commit is contained in:
@@ -165,6 +165,7 @@ namespace Tgstation.Server.Host.Components.Byond
|
||||
ActiveVersion?.ToString(),
|
||||
stringVersion,
|
||||
},
|
||||
false,
|
||||
cancellationToken);
|
||||
|
||||
ActiveVersion = version;
|
||||
@@ -475,7 +476,7 @@ namespace Tgstation.Server.Host.Components.Byond
|
||||
progressReporter.StageName = "Running event";
|
||||
|
||||
var versionString = version.ToString();
|
||||
await eventConsumer.HandleEvent(EventType.ByondInstallStart, new List<string> { versionString }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.ByondInstallStart, new List<string> { versionString }, false, cancellationToken);
|
||||
|
||||
await InstallVersionFiles(progressReporter, version, customVersionStream, cancellationToken);
|
||||
|
||||
@@ -484,7 +485,7 @@ namespace Tgstation.Server.Host.Components.Byond
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is not OperationCanceledException)
|
||||
await eventConsumer.HandleEvent(EventType.ByondInstallFail, new List<string> { ex.Message }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.ByondInstallFail, new List<string> { ex.Message }, false, cancellationToken);
|
||||
|
||||
lock (installedVersions)
|
||||
installedVersions.Remove(version);
|
||||
|
||||
@@ -448,7 +448,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
async Task DeleteCompileJobContent(string directory, CancellationToken cancellationToken)
|
||||
{
|
||||
// Then call the cleanup event, waiting here first
|
||||
await eventConsumer.HandleEvent(EventType.DeploymentCleanup, new List<string> { ioManager.ResolvePath(directory) }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.DeploymentCleanup, new List<string> { ioManager.ResolvePath(directory) }, true, cancellationToken);
|
||||
await ioManager.DeleteDirectory(directory, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
repoName,
|
||||
cancellationToken);
|
||||
|
||||
var eventTask = eventConsumer.HandleEvent(EventType.DeploymentComplete, Enumerable.Empty<string>(), cancellationToken);
|
||||
var eventTask = eventConsumer.HandleEvent(EventType.DeploymentComplete, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -537,7 +537,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
{
|
||||
// DCT: Cancellation token is for job, delaying here is fine
|
||||
progressReporter.StageName = "Running CompileCancelled event";
|
||||
await eventConsumer.HandleEvent(EventType.CompileCancelled, Enumerable.Empty<string>(), CancellationToken.None);
|
||||
await eventConsumer.HandleEvent(EventType.CompileCancelled, Enumerable.Empty<string>(), true, CancellationToken.None);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
@@ -594,6 +594,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
repoOrigin.ToString(),
|
||||
$"{byondLock.Version.Major}.{byondLock.Version.Minor}",
|
||||
},
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
// determine the dme
|
||||
@@ -632,6 +633,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
repoOrigin.ToString(),
|
||||
$"{byondLock.Version.Major}.{byondLock.Version.Minor}",
|
||||
},
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
// run compiler
|
||||
@@ -672,6 +674,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
exitCode == 0 ? "1" : "0",
|
||||
byondVersion.ToString(),
|
||||
},
|
||||
true,
|
||||
cancellationToken);
|
||||
throw;
|
||||
}
|
||||
@@ -684,6 +687,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
resolvedOutputDirectory,
|
||||
byondVersion.ToString(),
|
||||
},
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
logger.LogTrace("Applying static game file symlinks...");
|
||||
@@ -957,7 +961,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
try
|
||||
{
|
||||
// DCT: None available
|
||||
await eventConsumer.HandleEvent(EventType.DeploymentCleanup, new List<string> { jobPath }, CancellationToken.None);
|
||||
await eventConsumer.HandleEvent(EventType.DeploymentCleanup, new List<string> { jobPath }, true, CancellationToken.None);
|
||||
await ioManager.DeleteDirectory(jobPath, CancellationToken.None);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -31,15 +31,15 @@ namespace Tgstation.Server.Host.Components.Events
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
|
||||
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(parameters);
|
||||
|
||||
if (watchdog == null)
|
||||
throw new InvalidOperationException("EventConsumer used without watchdog set!");
|
||||
|
||||
var scriptTask = configuration.HandleEvent(eventType, parameters, cancellationToken);
|
||||
await watchdog.HandleEvent(eventType, parameters, cancellationToken);
|
||||
var scriptTask = configuration.HandleEvent(eventType, parameters, deploymentPipeline, cancellationToken);
|
||||
await watchdog.HandleEvent(eventType, parameters, deploymentPipeline, cancellationToken);
|
||||
await scriptTask;
|
||||
}
|
||||
|
||||
@@ -49,11 +49,10 @@ namespace Tgstation.Server.Host.Components.Events
|
||||
/// <param name="watchdog">The value of <see cref="watchdog"/>.</param>
|
||||
public void SetWatchdog(IWatchdog watchdog)
|
||||
{
|
||||
#pragma warning disable IDE0016 // Use 'throw' expression
|
||||
ArgumentNullException.ThrowIfNull(watchdog);
|
||||
#pragma warning restore IDE0016 // Use 'throw' expression
|
||||
if (this.watchdog != null)
|
||||
throw new InvalidOperationException("watchdog already set!");
|
||||
|
||||
this.watchdog = watchdog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ namespace Tgstation.Server.Host.Components.Events
|
||||
/// </summary>
|
||||
/// <param name="eventType">The <see cref="EventType"/>.</param>
|
||||
/// <param name="parameters">An <see cref="IEnumerable{T}"/> of <see cref="string"/> parameters for <paramref name="eventType"/>.</param>
|
||||
/// <param name="deploymentPipeline">If this event is part of the deployment pipeline.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
|
||||
Task HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken);
|
||||
Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,9 +306,10 @@ namespace Tgstation.Server.Host.Components
|
||||
|
||||
// the main point of auto update is to pull the remote
|
||||
await repo.FetchOrigin(
|
||||
NextProgressReporter("Fetch Origin"),
|
||||
repositorySettings.AccessUser,
|
||||
repositorySettings.AccessToken,
|
||||
NextProgressReporter("Fetch Origin"),
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
var hasDbChanges = false;
|
||||
@@ -380,9 +381,10 @@ namespace Tgstation.Server.Host.Components
|
||||
await UpdateRevInfo(repo.Head, false, null);
|
||||
|
||||
var result = await repo.MergeOrigin(
|
||||
NextProgressReporter("Merge Origin"),
|
||||
repositorySettings.CommitterName,
|
||||
repositorySettings.CommitterEmail,
|
||||
NextProgressReporter("Merge Origin"),
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
var preserveTestMerges = repositorySettings.AutoUpdatesKeepTestMerges.Value;
|
||||
@@ -428,10 +430,11 @@ namespace Tgstation.Server.Host.Components
|
||||
const string StageName = "Resetting to origin...";
|
||||
logger.LogTrace(StageName);
|
||||
await repo.ResetToOrigin(
|
||||
NextProgressReporter(StageName),
|
||||
repositorySettings.AccessUser,
|
||||
repositorySettings.AccessToken,
|
||||
repositorySettings.UpdateSubmodules.Value,
|
||||
NextProgressReporter(StageName),
|
||||
true,
|
||||
cancellationToken);
|
||||
|
||||
var currentHead = repo.Head;
|
||||
@@ -451,12 +454,13 @@ namespace Tgstation.Server.Host.Components
|
||||
if (repositorySettings.AutoUpdatesSynchronize.Value && startSha != repo.Head && (shouldSyncTracked || repositorySettings.PushTestMergeCommits.Value))
|
||||
{
|
||||
var pushedOrigin = await repo.Sychronize(
|
||||
NextProgressReporter("Synchronize"),
|
||||
repositorySettings.AccessUser,
|
||||
repositorySettings.AccessToken,
|
||||
repositorySettings.CommitterName,
|
||||
repositorySettings.CommitterEmail,
|
||||
NextProgressReporter("Synchronize"),
|
||||
shouldSyncTracked,
|
||||
true,
|
||||
cancellationToken);
|
||||
var currentHead = repo.Head;
|
||||
if (currentHead != currentRevInfo.CommitSha)
|
||||
@@ -492,7 +496,7 @@ namespace Tgstation.Server.Host.Components
|
||||
{
|
||||
await asyncDelayer.Delay(TimeSpan.FromMinutes(minutes > Int32.MaxValue ? Int32.MaxValue : minutes), cancellationToken);
|
||||
logger.LogInformation("Beginning auto update...");
|
||||
await eventConsumer.HandleEvent(EventType.InstanceAutoUpdateStart, Enumerable.Empty<string>(), cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.InstanceAutoUpdateStart, Enumerable.Empty<string>(), true, cancellationToken);
|
||||
try
|
||||
{
|
||||
var repositoryUpdateJob = new Job
|
||||
|
||||
@@ -281,7 +281,8 @@ namespace Tgstation.Server.Host.Components
|
||||
platformIdentifier,
|
||||
fileTransferService,
|
||||
loggerFactory.CreateLogger<StaticFiles.Configuration>(),
|
||||
generalConfiguration);
|
||||
generalConfiguration,
|
||||
sessionConfiguration);
|
||||
var eventConsumer = new EventConsumer(configuration);
|
||||
var repoManager = new RepositoryManager(
|
||||
repositoryFactory,
|
||||
|
||||
@@ -83,31 +83,35 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
/// <summary>
|
||||
/// Fetch commits from the origin repository.
|
||||
/// </summary>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="username">The username to fetch from the origin repository.</param>
|
||||
/// <param name="password">The password to fetch from the origin repository.</param>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
|
||||
Task FetchOrigin(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
JobProgressReporter progressReporter,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Requires the current HEAD to be a tracked reference. Hard resets the reference to what it tracks on the origin repository.
|
||||
/// </summary>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="username">The username used for fetching from submodule repositories.</param>
|
||||
/// <param name="password">The password used for fetching from submodule repositories.</param>
|
||||
/// <param name="updateSubmodules">If a submodule update should be attempted after the merge.</param>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the SHA of the new HEAD.</returns>
|
||||
Task ResetToOrigin(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
bool updateSubmodules,
|
||||
JobProgressReporter progressReporter,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
@@ -122,31 +126,39 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
/// <summary>
|
||||
/// Requires the current HEAD to be a tracked reference. Merges the reference to what it tracks on the origin repository.
|
||||
/// </summary>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="committerName">The name of the merge committer.</param>
|
||||
/// <param name="committerEmail">The e-mail of the merge committer.</param>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Nullable{T}"/> <see cref="bool"/> representing the merge result that is <see langword="true"/> after a fast forward, <see langword="false"/> on a merge or up to date, <see langword="null"/> on a conflict.</returns>
|
||||
Task<bool?> MergeOrigin(string committerName, string committerEmail, JobProgressReporter progressReporter, CancellationToken cancellationToken);
|
||||
Task<bool?> MergeOrigin(
|
||||
JobProgressReporter progressReporter,
|
||||
string committerName,
|
||||
string committerEmail,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Runs the synchronize event script and attempts to push any changes made to the <see cref="IRepository"/> if on a tracked branch.
|
||||
/// </summary>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="username">The username to fetch from the origin repository.</param>
|
||||
/// <param name="password">The password to fetch from the origin repository.</param>
|
||||
/// <param name="committerName">The name of the potential committer.</param>
|
||||
/// <param name="committerEmail">The e-mail of the potential committer.</param>
|
||||
/// <param name="progressReporter">The <see cref="JobProgressReporter"/> to report progress of the operation.</param>
|
||||
/// <param name="synchronizeTrackedBranch">If the synchronizations should be made to the tracked reference as opposed to a temporary branch.</param>
|
||||
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if commits were pushed to the tracked origin reference, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> Sychronize(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
string committerName,
|
||||
string committerEmail,
|
||||
JobProgressReporter progressReporter,
|
||||
bool synchronizeTrackedBranch,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -333,6 +333,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
await eventConsumer.HandleEvent(
|
||||
EventType.RepoMergeConflict,
|
||||
arguments,
|
||||
false,
|
||||
cancellationToken);
|
||||
return new TestMergeResult
|
||||
{
|
||||
@@ -359,6 +360,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
progressReporter.CreateSection("Update Submodules", progressFactor),
|
||||
username,
|
||||
password,
|
||||
false,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -371,6 +373,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
testMergeParameters.TargetCommitSha,
|
||||
testMergeParameters.Comment,
|
||||
},
|
||||
false,
|
||||
cancellationToken);
|
||||
|
||||
return new TestMergeResult
|
||||
@@ -392,7 +395,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
ArgumentNullException.ThrowIfNull(committish);
|
||||
ArgumentNullException.ThrowIfNull(progressReporter);
|
||||
logger.LogDebug("Checkout object: {committish}...", committish);
|
||||
await eventConsumer.HandleEvent(EventType.RepoCheckout, new List<string> { committish }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.RepoCheckout, new List<string> { committish }, false, cancellationToken);
|
||||
await Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
@@ -411,15 +414,21 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
progressReporter.CreateSection(null, 1.0 / 3),
|
||||
username,
|
||||
password,
|
||||
false,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task FetchOrigin(string username, string password, JobProgressReporter progressReporter, CancellationToken cancellationToken)
|
||||
public async Task FetchOrigin(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(progressReporter);
|
||||
logger.LogDebug("Fetch origin...");
|
||||
await eventConsumer.HandleEvent(EventType.RepoFetch, Enumerable.Empty<string>(), cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.RepoFetch, Enumerable.Empty<string>(), deploymentPipeline, cancellationToken);
|
||||
await Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
@@ -458,10 +467,11 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ResetToOrigin(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
bool updateSubmodules,
|
||||
JobProgressReporter progressReporter,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(progressReporter);
|
||||
@@ -469,7 +479,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
throw new JobException(ErrorCode.RepoReferenceRequired);
|
||||
logger.LogTrace("Reset to origin...");
|
||||
var trackedBranch = libGitRepo.Head.TrackedBranch;
|
||||
await eventConsumer.HandleEvent(EventType.RepoResetOrigin, new List<string> { trackedBranch.FriendlyName, trackedBranch.Tip.Sha }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(EventType.RepoResetOrigin, new List<string> { trackedBranch.FriendlyName, trackedBranch.Tip.Sha }, deploymentPipeline, cancellationToken);
|
||||
await ResetToSha(
|
||||
trackedBranch.Tip.Sha,
|
||||
progressReporter.CreateSection(null, updateSubmodules ? 2.0 / 3 : 1.0),
|
||||
@@ -480,6 +490,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
progressReporter.CreateSection(null, 1.0 / 3),
|
||||
username,
|
||||
password,
|
||||
deploymentPipeline,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
@@ -547,9 +558,10 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool?> MergeOrigin(
|
||||
JobProgressReporter progressReporter,
|
||||
string committerName,
|
||||
string committerEmail,
|
||||
JobProgressReporter progressReporter,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(progressReporter);
|
||||
@@ -606,7 +618,17 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
|
||||
if (result.Status == MergeStatus.Conflicts)
|
||||
{
|
||||
await eventConsumer.HandleEvent(EventType.RepoMergeConflict, new List<string> { oldTip.Sha, trackedBranch.Tip.Sha, oldHead.FriendlyName ?? UnknownReference, trackedBranch.FriendlyName }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(
|
||||
EventType.RepoMergeConflict,
|
||||
new List<string>
|
||||
{
|
||||
oldTip.Sha,
|
||||
trackedBranch.Tip.Sha,
|
||||
oldHead.FriendlyName ?? UnknownReference,
|
||||
trackedBranch.FriendlyName,
|
||||
},
|
||||
deploymentPipeline,
|
||||
cancellationToken);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -615,12 +637,13 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Sychronize(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
string committerName,
|
||||
string committerEmail,
|
||||
JobProgressReporter progressReporter,
|
||||
bool synchronizeTrackedBranch,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(committerName);
|
||||
@@ -661,6 +684,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
{
|
||||
ioMananger.ResolvePath(),
|
||||
},
|
||||
deploymentPipeline,
|
||||
cancellationToken);
|
||||
}
|
||||
finally
|
||||
@@ -964,9 +988,15 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
/// <param name="progressReporter"><see cref="JobProgressReporter"/> of the operation.</param>
|
||||
/// <param name="username">The username for the <see cref="credentialsProvider"/>.</param>
|
||||
/// <param name="password">The password for the <see cref="credentialsProvider"/>.</param>
|
||||
/// <param name="deploymentPipeline">If any events created should be marked as part of the deployment pipeline.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
|
||||
async Task UpdateSubmodules(JobProgressReporter progressReporter, string username, string password, CancellationToken cancellationToken)
|
||||
async Task UpdateSubmodules(
|
||||
JobProgressReporter progressReporter,
|
||||
string username,
|
||||
string password,
|
||||
bool deploymentPipeline,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var submoduleCount = libGitRepo.Submodules.Count();
|
||||
if (submoduleCount == 0)
|
||||
@@ -1032,7 +1062,11 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
}
|
||||
}
|
||||
|
||||
await eventConsumer.HandleEvent(EventType.RepoSubmoduleUpdate, new List<string> { submodule.Name }, cancellationToken);
|
||||
await eventConsumer.HandleEvent(
|
||||
EventType.RepoSubmoduleUpdate,
|
||||
new List<string> { submodule.Name },
|
||||
deploymentPipeline,
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,11 +152,10 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
CancellationToken cancellationToken)
|
||||
#pragma warning restore CA1502, CA1506
|
||||
{
|
||||
var repoManager = instance.RepositoryManager;
|
||||
using var repo = await repoManager.LoadRepository(cancellationToken);
|
||||
if (repo == null)
|
||||
throw new JobException(ErrorCode.RepoMissing);
|
||||
_ = job; // shuts up an IDE warning
|
||||
|
||||
var repoManager = instance.RepositoryManager;
|
||||
using var repo = await repoManager.LoadRepository(cancellationToken) ?? throw new JobException(ErrorCode.RepoMissing);
|
||||
var modelHasShaOrReference = model.CheckoutSha != null || model.Reference != null;
|
||||
|
||||
var startReference = repo.Reference;
|
||||
@@ -252,11 +251,21 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
{
|
||||
if (!repo.Tracking)
|
||||
throw new JobException(ErrorCode.RepoReferenceRequired);
|
||||
await repo.FetchOrigin(currentModel.AccessUser, currentModel.AccessToken, NextProgressReporter("Fetch Origin"), cancellationToken);
|
||||
await repo.FetchOrigin(
|
||||
NextProgressReporter("Fetch Origin"),
|
||||
currentModel.AccessUser,
|
||||
currentModel.AccessToken,
|
||||
false,
|
||||
cancellationToken);
|
||||
|
||||
if (!modelHasShaOrReference)
|
||||
{
|
||||
var fastForward = await repo.MergeOrigin(committerName, currentModel.CommitterEmail, NextProgressReporter("Merge Origin"), cancellationToken);
|
||||
var fastForward = await repo.MergeOrigin(
|
||||
NextProgressReporter("Merge Origin"),
|
||||
committerName,
|
||||
currentModel.CommitterEmail,
|
||||
false,
|
||||
cancellationToken);
|
||||
if (!fastForward.HasValue)
|
||||
throw new JobException(ErrorCode.RepoMergeConflict);
|
||||
lastRevisionInfo.OriginCommitSha = await repo.GetOriginSha(cancellationToken);
|
||||
@@ -264,12 +273,13 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
if (fastForward.Value)
|
||||
{
|
||||
await repo.Sychronize(
|
||||
NextProgressReporter("Sychronize"),
|
||||
currentModel.AccessUser,
|
||||
currentModel.AccessToken,
|
||||
currentModel.CommitterName,
|
||||
currentModel.CommitterEmail,
|
||||
NextProgressReporter("Sychronize"),
|
||||
true,
|
||||
false,
|
||||
cancellationToken);
|
||||
postUpdateSha = repo.Head;
|
||||
}
|
||||
@@ -315,18 +325,20 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
if (!repo.Tracking)
|
||||
throw new JobException(ErrorCode.RepoReferenceNotTracking);
|
||||
await repo.ResetToOrigin(
|
||||
NextProgressReporter("Reset to Origin"),
|
||||
currentModel.AccessUser,
|
||||
currentModel.AccessToken,
|
||||
updateSubmodules,
|
||||
NextProgressReporter("Reset to Origin"),
|
||||
false,
|
||||
cancellationToken);
|
||||
await repo.Sychronize(
|
||||
NextProgressReporter("Synchronize"),
|
||||
currentModel.AccessUser,
|
||||
currentModel.AccessToken,
|
||||
currentModel.CommitterName,
|
||||
currentModel.CommitterEmail,
|
||||
NextProgressReporter("Synchronize"),
|
||||
true,
|
||||
false,
|
||||
cancellationToken);
|
||||
await CallLoadRevInfo();
|
||||
|
||||
@@ -473,7 +485,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
if (revInfoWereLookingFor != null)
|
||||
{
|
||||
// goteem
|
||||
logger.LogDebug("Reusing existing SHA {0}...", revInfoWereLookingFor.CommitSha);
|
||||
logger.LogDebug("Reusing existing SHA {sha}...", revInfoWereLookingFor.CommitSha);
|
||||
await repo.ResetToSha(revInfoWereLookingFor.CommitSha, NextProgressReporter($"Reset to {revInfoWereLookingFor.CommitSha[..7]}"), cancellationToken);
|
||||
lastRevisionInfo = revInfoWereLookingFor;
|
||||
}
|
||||
@@ -535,11 +547,12 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
if (currentModel.PushTestMergeCommits.Value && (startSha != currentHead || (postUpdateSha != null && postUpdateSha != currentHead)))
|
||||
{
|
||||
await repo.Sychronize(
|
||||
NextProgressReporter("Synchronize"),
|
||||
currentModel.AccessUser,
|
||||
currentModel.AccessToken,
|
||||
currentModel.CommitterName,
|
||||
currentModel.CommitterEmail,
|
||||
NextProgressReporter("Synchronize"),
|
||||
false,
|
||||
false,
|
||||
cancellationToken);
|
||||
await UpdateRevInfo();
|
||||
|
||||
@@ -549,6 +549,7 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
{
|
||||
process.Id.ToString(CultureInfo.InvariantCulture),
|
||||
},
|
||||
false,
|
||||
cancellationToken);
|
||||
|
||||
return process;
|
||||
|
||||
@@ -128,6 +128,11 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
/// </summary>
|
||||
readonly GeneralConfiguration generalConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SessionConfiguration"/> for <see cref="Configuration"/>.
|
||||
/// </summary>
|
||||
readonly SessionConfiguration sessionConfiguration;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SemaphoreSlim"/> for <see cref="Configuration"/>. Also used as a <see langword="lock"/> <see cref="object"/>.
|
||||
/// </summary>
|
||||
@@ -155,6 +160,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
/// <param name="fileTransferService">The value of <see cref="fileTransferService"/>.</param>
|
||||
/// <param name="logger">The value of <see cref="logger"/>.</param>
|
||||
/// <param name="generalConfiguration">The value of <see cref="generalConfiguration"/>.</param>
|
||||
/// <param name="sessionConfiguration">The value of <see cref="sessionConfiguration"/>.</param>
|
||||
public Configuration(
|
||||
IIOManager ioManager,
|
||||
ISynchronousIOManager synchronousIOManager,
|
||||
@@ -164,7 +170,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
IPlatformIdentifier platformIdentifier,
|
||||
IFileTransferTicketProvider fileTransferService,
|
||||
ILogger<Configuration> logger,
|
||||
GeneralConfiguration generalConfiguration)
|
||||
GeneralConfiguration generalConfiguration,
|
||||
SessionConfiguration sessionConfiguration)
|
||||
{
|
||||
this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
|
||||
this.synchronousIOManager = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager));
|
||||
@@ -175,6 +182,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
this.fileTransferService = fileTransferService ?? throw new ArgumentNullException(nameof(fileTransferService));
|
||||
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
this.generalConfiguration = generalConfiguration ?? throw new ArgumentNullException(nameof(generalConfiguration));
|
||||
this.sessionConfiguration = sessionConfiguration ?? throw new ArgumentNullException(nameof(sessionConfiguration));
|
||||
|
||||
semaphore = new SemaphoreSlim(1);
|
||||
disposeCts = new CancellationTokenSource();
|
||||
@@ -592,7 +600,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
public Task StopAsync(CancellationToken cancellationToken) => EnsureDirectories(cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
|
||||
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(parameters);
|
||||
|
||||
@@ -639,6 +647,9 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
noShellExecute: true))
|
||||
using (cancellationToken.Register(() => script.Terminate()))
|
||||
{
|
||||
if (sessionConfiguration.LowPriorityDeploymentProcesses)
|
||||
script.AdjustPriority(false);
|
||||
|
||||
var exitCode = await script.Lifetime;
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var scriptOutput = await script.GetCombinedOutput(cancellationToken);
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
var eventType = Server.TerminationWasRequested
|
||||
? EventType.WorldEndProcess
|
||||
: EventType.WatchdogCrash;
|
||||
await HandleEvent(eventType, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
await HandleEventImpl(eventType, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
|
||||
var exitWord = Server.TerminationWasRequested ? "exited" : "crashed";
|
||||
if (Server.RebootState == Session.RebootState.Shutdown)
|
||||
@@ -143,7 +143,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
gracefulRebootRequired = false;
|
||||
Server.ResetRebootState();
|
||||
|
||||
var eventTask = HandleEvent(EventType.WorldReboot, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
var eventTask = HandleEventImpl(EventType.WorldReboot, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
try
|
||||
{
|
||||
switch (rebootState)
|
||||
@@ -174,7 +174,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
await HandleNewDmbAvailable(cancellationToken);
|
||||
break;
|
||||
case MonitorActivationReason.ActiveServerPrimed:
|
||||
await HandleEvent(EventType.WorldPrime, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
await HandleEventImpl(EventType.WorldPrime, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
break;
|
||||
case MonitorActivationReason.ActiveServerStartup:
|
||||
break; // unused in BasicWatchdog
|
||||
|
||||
@@ -449,7 +449,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task IEventConsumer.HandleEvent(EventType eventType, IEnumerable<string> parameters, CancellationToken cancellationToken)
|
||||
async Task IEventConsumer.HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(parameters);
|
||||
|
||||
@@ -509,7 +509,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
? "Launching..."
|
||||
: "Reattaching..."); // simple announce
|
||||
if (reattachInfo == null)
|
||||
eventTask = HandleEvent(EventType.WatchdogLaunch, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
eventTask = HandleEventImpl(EventType.WatchdogLaunch, Enumerable.Empty<string>(), false, cancellationToken);
|
||||
}
|
||||
|
||||
// since neither server is running, this is safe to do
|
||||
@@ -693,13 +693,13 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
/// <param name="relayToSession">If the event should be sent to DreamDaemon.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
|
||||
protected async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool relayToSession, CancellationToken cancellationToken)
|
||||
protected async Task HandleEventImpl(EventType eventType, IEnumerable<string> parameters, bool relayToSession, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sessionEventTask = relayToSession ? ((IEventConsumer)this).HandleEvent(eventType, parameters, cancellationToken) : Task.CompletedTask;
|
||||
var sessionEventTask = relayToSession ? ((IEventConsumer)this).HandleEvent(eventType, parameters, false, cancellationToken) : Task.CompletedTask;
|
||||
await Task.WhenAll(
|
||||
eventConsumer.HandleEvent(eventType, parameters, cancellationToken),
|
||||
eventConsumer.HandleEvent(eventType, parameters, false, cancellationToken),
|
||||
sessionEventTask);
|
||||
}
|
||||
catch (JobException ex)
|
||||
@@ -1005,7 +1005,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
return;
|
||||
if (!graceful)
|
||||
{
|
||||
var eventTask = HandleEvent(
|
||||
var eventTask = HandleEventImpl(
|
||||
releaseServers
|
||||
? EventType.WatchdogDetach
|
||||
: EventType.WatchdogShutdown,
|
||||
|
||||
Reference in New Issue
Block a user