Even more ValueTask conversions

This commit is contained in:
Jordan Dominion
2023-10-07 14:59:08 -04:00
parent 9129638bb5
commit dc52156e0e
18 changed files with 151 additions and 146 deletions
@@ -631,8 +631,8 @@ namespace Tgstation.Server.Host.Components.Chat
/// </summary>
/// <param name="provider">The <see cref="IProvider"/> to remap channels for.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task RemapProvider(IProvider provider, CancellationToken cancellationToken)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask RemapProvider(IProvider provider, CancellationToken cancellationToken)
{
logger.LogTrace("Remapping channels for provider reconnection...");
IEnumerable<Models.ChatChannel> channelsToMap;
@@ -654,9 +654,9 @@ namespace Tgstation.Server.Host.Components.Chat
/// <param name="message">The <see cref="Message"/> to process. If <see langword="null"/>, this indicates the provider reconnected.</param>
/// <param name="recursed">If we are called recursively after remapping the provider.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
#pragma warning disable CA1502
async Task ProcessMessage(IProvider provider, Message message, bool recursed, CancellationToken cancellationToken)
async ValueTask ProcessMessage(IProvider provider, Message message, bool recursed, CancellationToken cancellationToken)
#pragma warning restore CA1502
{
if (!provider.Connected)
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Deployment.Remote;
using Tgstation.Server.Host.Components.Events;
using Tgstation.Server.Host.Database;
@@ -420,7 +421,7 @@ namespace Tgstation.Server.Host.Components.Deployment
{
try
{
await Task.WhenAll(deleteTask, deploymentJob);
await ValueTaskExtensions.WhenAll(deleteTask, deploymentJob);
}
catch (Exception ex)
{
@@ -453,8 +454,8 @@ namespace Tgstation.Server.Host.Components.Deployment
/// </summary>
/// <param name="directory">The directory to cleanup.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for this <see cref="Task"/>.</param>
/// <returns>The deletion <see cref="Task"/>.</returns>
async Task DeleteCompileJobContent(string directory, CancellationToken cancellationToken)
/// <returns>The deletion <see cref="ValueTask"/>.</returns>
async ValueTask DeleteCompileJobContent(string directory, CancellationToken cancellationToken)
{
// Then call the cleanup event, waiting here first
await eventConsumer.HandleEvent(EventType.DeploymentCleanup, new List<string> { ioManager.ResolvePath(directory) }, true, cancellationToken);
@@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Byond;
using Tgstation.Server.Host.Components.Chat;
using Tgstation.Server.Host.Components.Deployment.Remote;
@@ -390,7 +391,7 @@ namespace Tgstation.Server.Host.Components.Deployment
try
{
await Task.WhenAll(commentsTask, eventTask);
await ValueTaskExtensions.WhenAll(commentsTask, eventTask);
}
catch (Exception ex)
{
@@ -950,10 +951,10 @@ namespace Tgstation.Server.Host.Components.Deployment
/// <param name="job">The running <see cref="CompileJob"/>.</param>
/// <param name="remoteDeploymentManager">The <see cref="IRemoteDeploymentManager"/> associated with the <paramref name="job"/>.</param>
/// <param name="exception">The <see cref="Exception"/> that was thrown.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task CleanupFailedCompile(Models.CompileJob job, IRemoteDeploymentManager remoteDeploymentManager, Exception exception)
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask CleanupFailedCompile(Models.CompileJob job, IRemoteDeploymentManager remoteDeploymentManager, Exception exception)
{
async Task CleanDir()
async ValueTask CleanDir()
{
logger.LogTrace("Cleaning compile directory...");
var jobPath = job.DirectoryName.ToString();
@@ -970,7 +971,7 @@ namespace Tgstation.Server.Host.Components.Deployment
}
// DCT: None available
await Task.WhenAll(
return ValueTaskExtensions.WhenAll(
CleanDir(),
remoteDeploymentManager.FailDeployment(
job,
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Repository;
using Tgstation.Server.Host.Models;
@@ -49,7 +50,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public async Task PostDeploymentComments(
public async ValueTask PostDeploymentComments(
CompileJob compileJob,
RevisionInformation previousRevisionInformation,
RepositorySettings repositorySettings,
@@ -102,7 +103,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
removedTestMerges.Count,
updatedTestMerges.Count);
var tasks = new List<Task>(addedTestMerges.Count + updatedTestMerges.Count + removedTestMerges.Count);
var tasks = new List<ValueTask>(addedTestMerges.Count + updatedTestMerges.Count + removedTestMerges.Count);
foreach (var addedTestMerge in addedTestMerges)
tasks.Add(
CommentOnTestMergeSource(
@@ -146,11 +147,11 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken));
if (tasks.Any())
await Task.WhenAll(tasks);
await ValueTaskExtensions.WhenAll(tasks);
}
/// <inheritdoc />
public Task ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken)
public ValueTask ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -161,10 +162,10 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public abstract Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
public abstract ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
/// <inheritdoc />
public Task MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
public ValueTask MarkInactive(CompileJob compileJob, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -175,14 +176,14 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public abstract Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
public abstract ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
CancellationToken cancellationToken);
/// <inheritdoc />
public Task StageDeployment(CompileJob compileJob, Action<bool> activationCallback, CancellationToken cancellationToken)
public ValueTask StageDeployment(CompileJob compileJob, Action<bool> activationCallback, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(compileJob);
@@ -193,7 +194,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public abstract Task StartDeployment(
public abstract ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken);
@@ -203,24 +204,24 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// </summary>
/// <param name="compileJob">The staged <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Implementation of <see cref="ApplyDeployment(CompileJob, CancellationToken)"/>.
/// </summary>
/// <param name="compileJob">The <see cref="CompileJob"/> being applied.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Implementation of <see cref="MarkInactive(CompileJob, CancellationToken)"/>.
/// </summary>
/// <param name="compileJob">The inactive <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Formats a comment for a given <paramref name="testMerge"/>.
@@ -231,7 +232,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="remoteRepositoryOwner">The <see cref="Api.Models.Internal.IGitRemoteInformation.RemoteRepositoryOwner"/>.</param>
/// <param name="remoteRepositoryName">The <see cref="Api.Models.Internal.IGitRemoteInformation.RemoteRepositoryName"/>.</param>
/// <param name="updated">If <see langword="false"/> <paramref name="testMerge"/> is new, otherwise it has been updated to a different <see cref="Api.Models.TestMergeParameters.TargetCommitSha"/>.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
/// <returns>A formatted <see cref="string"/> for posting a informative comment about the <paramref name="testMerge"/>.</returns>
protected abstract string FormatTestMerge(
RepositorySettings repositorySettings,
CompileJob compileJob,
@@ -249,8 +250,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="comment">The comment to post.</param>
/// <param name="testMergeNumber">The <see cref="Api.Models.TestMergeParameters.Number"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task CommentOnTestMergeSource(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected abstract ValueTask CommentOnTestMergeSource(
RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
@@ -55,7 +55,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override async Task StartDeployment(
public override async ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken)
@@ -148,7 +148,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
public override ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
=> UpdateDeployment(
compileJob,
errorMessage,
@@ -156,7 +156,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
public override async Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
public override async ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
@@ -191,7 +191,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
var newList = revisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList();
PullRequest lastMerged = null;
async Task CheckRemovePR(Task<PullRequest> task)
async ValueTask CheckRemovePR(Task<PullRequest> task)
{
var pr = await task;
if (!pr.Merged)
@@ -215,7 +215,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
protected override Task StageDeploymentImpl(
protected override ValueTask StageDeploymentImpl(
CompileJob compileJob,
CancellationToken cancellationToken)
=> UpdateDeployment(
@@ -225,7 +225,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
protected override Task ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
protected override ValueTask ApplyDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken)
=> UpdateDeployment(
compileJob,
"The deployment is now live on the server.",
@@ -233,7 +233,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
protected override Task MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
protected override ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken)
=> UpdateDeployment(
compileJob,
"The deployment has been superceeded.",
@@ -241,7 +241,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
cancellationToken);
/// <inheritdoc />
protected override async Task CommentOnTestMergeSource(
protected override async ValueTask CommentOnTestMergeSource(
RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
@@ -302,8 +302,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="description">A description of the update.</param>
/// <param name="deploymentState">The new <see cref="DeploymentState"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
async Task UpdateDeployment(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
async ValueTask UpdateDeployment(
CompileJob compileJob,
string description,
DeploymentState deploymentState,
@@ -36,7 +36,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override async Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
public override async ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
@@ -76,7 +76,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
var newList = revisionInformation.ActiveTestMerges.Select(x => x.TestMerge).ToList();
MergeRequest lastMerged = null;
async Task CheckRemoveMR(Task<MergeRequest> task)
async ValueTask CheckRemoveMR(Task<MergeRequest> task)
{
var mergeRequest = await task;
if (mergeRequest.State != MergeRequestState.Merged)
@@ -100,30 +100,30 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override Task FailDeployment(
public override ValueTask FailDeployment(
CompileJob compileJob,
string errorMessage,
CancellationToken cancellationToken) => Task.CompletedTask;
CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
public override Task StartDeployment(
public override ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken) => Task.CompletedTask;
CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task ApplyDeploymentImpl(
protected override ValueTask ApplyDeploymentImpl(
CompileJob compileJob,
CancellationToken cancellationToken) => Task.CompletedTask;
CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask StageDeploymentImpl(CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask MarkInactiveImpl(CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override async Task CommentOnTestMergeSource(
protected override async ValueTask CommentOnTestMergeSource(
RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
@@ -19,8 +19,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="remoteInformation">The <see cref="Api.Models.Internal.IGitRemoteInformation"/> of the repository being deployed.</param>
/// <param name="compileJob">The active <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task StartDeployment(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask StartDeployment(
Api.Models.Internal.IGitRemoteInformation remoteInformation,
CompileJob compileJob,
CancellationToken cancellationToken);
@@ -31,8 +31,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="compileJob">The staged <see cref="CompileJob"/>.</param>
/// <param name="activationCallback">An optional <see cref="Action{T1}"/> to be called when the <see cref="CompileJob"/> becomes active or is discarded with <see langword="true"/> or <see langword="false"/> respectively.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task StageDeployment(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask StageDeployment(
CompileJob compileJob,
Action<bool> activationCallback,
CancellationToken cancellationToken);
@@ -42,8 +42,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// </summary>
/// <param name="compileJob">The <see cref="CompileJob"/> being applied.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ApplyDeployment(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Fail a deployment for a given <paramref name="compileJob"/>.
@@ -51,8 +51,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="compileJob">The failed <see cref="CompileJob"/>.</param>
/// <param name="errorMessage">The error message.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask FailDeployment(CompileJob compileJob, string errorMessage, CancellationToken cancellationToken);
/// <summary>
/// Mark the deplotment for a given <paramref name="compileJob"/> as inactive.
@@ -60,7 +60,7 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="compileJob">The inactive <see cref="CompileJob"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task MarkInactive(CompileJob compileJob, CancellationToken cancellationToken);
ValueTask MarkInactive(CompileJob compileJob, CancellationToken cancellationToken);
/// <summary>
/// Post deployment comments to the test merge ticket.
@@ -71,8 +71,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="repoOwner">The GitHub repostiory owner.</param>
/// <param name="repoName">The GitHub repostiory name.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task PostDeploymentComments(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask PostDeploymentComments(
CompileJob compileJob,
RevisionInformation previousRevisionInformation,
RepositorySettings repositorySettings,
@@ -87,8 +87,8 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
/// <param name="repositorySettings">The <see cref="RepositorySettings"/>.</param>
/// <param name="revisionInformation">The current <see cref="RevisionInformation"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IReadOnlyCollection{T}"/> of <see cref="TestMerge"/>s that should remain the new <see cref="RevisionInformation"/>.</returns>
Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IReadOnlyCollection{T}"/> of <see cref="TestMerge"/>s that should remain the new <see cref="RevisionInformation"/>.</returns>
ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(
IRepository repository,
RepositorySettings repositorySettings,
RevisionInformation revisionInformation,
@@ -32,31 +32,31 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
}
/// <inheritdoc />
public override Task FailDeployment(Models.CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
public override ValueTask FailDeployment(Models.CompileJob compileJob, string errorMessage, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override Task<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(IRepository repository, Models.RepositorySettings repositorySettings, Models.RevisionInformation revisionInformation, CancellationToken cancellationToken)
=> Task.FromResult<IReadOnlyCollection<TestMerge>>(Array.Empty<TestMerge>());
public override ValueTask<IReadOnlyCollection<TestMerge>> RemoveMergedTestMerges(IRepository repository, Models.RepositorySettings repositorySettings, Models.RevisionInformation revisionInformation, CancellationToken cancellationToken)
=> ValueTask.FromResult<IReadOnlyCollection<TestMerge>>(Array.Empty<TestMerge>());
/// <inheritdoc />
public override Task StartDeployment(IGitRemoteInformation remoteInformation, Models.CompileJob compileJob, CancellationToken cancellationToken)
=> Task.CompletedTask;
public override ValueTask StartDeployment(IGitRemoteInformation remoteInformation, Models.CompileJob compileJob, CancellationToken cancellationToken)
=> ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task ApplyDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask ApplyDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
/// <inheritdoc />
protected override Task CommentOnTestMergeSource(
protected override ValueTask CommentOnTestMergeSource(
Models.RepositorySettings repositorySettings,
string remoteRepositoryOwner,
string remoteRepositoryName,
string comment,
int testMergeNumber,
CancellationToken cancellationToken)
=> Task.CompletedTask;
=> ValueTask.CompletedTask;
/// <inheritdoc />
protected override string FormatTestMerge(
@@ -69,12 +69,12 @@ namespace Tgstation.Server.Host.Components.Deployment.Remote
=> String.Empty;
/// <inheritdoc />
protected override Task MarkInactiveImpl(Models.CompileJob compileJob, CancellationToken cancellationToken)
protected override ValueTask MarkInactiveImpl(Models.CompileJob compileJob, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
/// <inheritdoc />
protected override Task StageDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => Task.CompletedTask;
protected override ValueTask StageDeploymentImpl(Models.CompileJob compileJob, CancellationToken cancellationToken) => ValueTask.CompletedTask;
}
}
@@ -31,7 +31,7 @@ namespace Tgstation.Server.Host.Components.Events
}
/// <inheritdoc />
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
public async ValueTask HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(parameters);
@@ -16,7 +16,7 @@ namespace Tgstation.Server.Host.Components.Events
/// <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, bool deploymentPipeline, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken);
}
}
@@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Events;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Extensions;
@@ -198,7 +199,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async Task<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken)
public async ValueTask<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken)
{
using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken))
{
@@ -236,7 +237,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async Task<IOrderedQueryable<ConfigurationFileResponse>> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<IOrderedQueryable<ConfigurationFileResponse>> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -283,7 +284,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async Task<ConfigurationFileResponse> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<ConfigurationFileResponse> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -393,7 +394,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async Task SymlinkStaticFilesTo(string destination, CancellationToken cancellationToken)
public async ValueTask SymlinkStaticFilesTo(string destination, CancellationToken cancellationToken)
{
async Task<IReadOnlyList<string>> GetIgnoreFiles()
{
@@ -416,7 +417,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
IReadOnlyList<string> ignoreFiles;
async Task SymlinkBase(bool files)
async ValueTask SymlinkBase(bool files)
{
Task<IReadOnlyList<string>> task;
if (files)
@@ -425,7 +426,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
task = ioManager.GetDirectories(GameStaticFilesSubdirectory, cancellationToken);
var entries = await task;
await Task.WhenAll(entries.Select(async file =>
await ValueTaskExtensions.WhenAll(entries.Select<string, ValueTask>(async file =>
{
var fileName = ioManager.GetFileName(file);
@@ -458,12 +459,12 @@ namespace Tgstation.Server.Host.Components.StaticFiles
{
await EnsureDirectories(cancellationToken);
ignoreFiles = await GetIgnoreFiles();
await Task.WhenAll(SymlinkBase(true), SymlinkBase(false));
await ValueTaskExtensions.WhenAll(SymlinkBase(true), SymlinkBase(false));
}
}
/// <inheritdoc />
public async Task<ConfigurationFileResponse> Write(string configurationRelativePath, ISystemIdentity systemIdentity, string previousHash, CancellationToken cancellationToken)
public async ValueTask<ConfigurationFileResponse> Write(string configurationRelativePath, ISystemIdentity systemIdentity, string previousHash, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -573,7 +574,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async Task<bool?> CreateDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<bool?> CreateDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -605,7 +606,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
public Task StopAsync(CancellationToken cancellationToken) => EnsureDirectories(cancellationToken);
/// <inheritdoc />
public async Task HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
public async ValueTask HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(parameters);
@@ -668,7 +669,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
}
/// <inheritdoc />
public async Task<bool?> DeleteDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
public async ValueTask<bool?> DeleteDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken)
{
await EnsureDirectories(cancellationToken);
var path = ValidateConfigRelativePath(configurationRelativePath);
@@ -21,16 +21,16 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="dmeFile">The .dme file being compiled.</param>
/// <param name="destination">Path to the destination folder.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ServerSideModifications"/> if any.</returns>
Task<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ServerSideModifications"/> if any.</returns>
ValueTask<ServerSideModifications> CopyDMFilesTo(string dmeFile, string destination, CancellationToken cancellationToken);
/// <summary>
/// Symlinks all directories in the GameData directory to <paramref name="destination"/>.
/// </summary>
/// <param name="destination">Path to the destination folder.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
Task SymlinkStaticFilesTo(string destination, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask SymlinkStaticFilesTo(string destination, CancellationToken cancellationToken);
/// <summary>
/// Get <see cref="ConfigurationFileResponse"/>s for all items in a given <paramref name="configurationRelativePath"/>.
@@ -38,8 +38,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="configurationRelativePath">The relative path in the Configuration directory.</param>
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in an <see cref="IOrderedQueryable{T}"/> of the <see cref="ConfigurationFileResponse"/>s for the items in the directory. <see cref="FileTicketResponse.FileTicket"/> and <see cref="IConfigurationFile.LastReadHash"/> will both be <see langword="null"/>. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
Task<IOrderedQueryable<ConfigurationFileResponse>> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in an <see cref="IOrderedQueryable{T}"/> of the <see cref="ConfigurationFileResponse"/>s for the items in the directory. <see cref="FileTicketResponse.FileTicket"/> and <see cref="IConfigurationFile.LastReadHash"/> will both be <see langword="null"/>. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
ValueTask<IOrderedQueryable<ConfigurationFileResponse>> ListDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <summary>
/// Reads a given <paramref name="configurationRelativePath"/>.
@@ -47,8 +47,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="configurationRelativePath">The relative path in the Configuration directory.</param>
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ConfigurationFileResponse"/> of the file. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
Task<ConfigurationFileResponse> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="ConfigurationFileResponse"/> of the file. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
ValueTask<ConfigurationFileResponse> Read(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <summary>
/// Create an empty directory at <paramref name="configurationRelativePath"/>.
@@ -56,8 +56,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="configurationRelativePath">The relative path in the Configuration directory.</param>
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation. Usage may result in partial writes.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="true"/> if the directory already existed, <see langword="false"/> otherwise. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
Task<bool?> CreateDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if the directory already existed, <see langword="false"/> otherwise. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
ValueTask<bool?> CreateDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <summary>
/// Attempt to delete an empty directory at <paramref name="configurationRelativePath"/>.
@@ -65,8 +65,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="configurationRelativePath">The path of the empty directory to delete.</param>
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns><see langword="true"/> if the directory was empty and deleted, <see langword="false"/> otherwise. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
Task<bool?> DeleteDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in <see langword="true"/> if the directory was empty and deleted, <see langword="false"/> otherwise. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
ValueTask<bool?> DeleteDirectory(string configurationRelativePath, ISystemIdentity systemIdentity, CancellationToken cancellationToken);
/// <summary>
/// Writes to a given <paramref name="configurationRelativePath"/>.
@@ -75,7 +75,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
/// <param name="systemIdentity">The <see cref="ISystemIdentity"/> for the operation. If <see langword="null"/>, the operation will be performed as the user of the <see cref="Core.Application"/>.</param>
/// <param name="previousHash">The hash any existing file must match in order for the write to succeed.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation. Usage may result in partial writes.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the updated <see cref="ConfigurationFileResponse"/> and associated writing <see cref="FileTicketResponse"/>. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
Task<ConfigurationFileResponse> Write(string configurationRelativePath, ISystemIdentity systemIdentity, string previousHash, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the updated <see cref="ConfigurationFileResponse"/> and associated writing <see cref="FileTicketResponse"/>. <see langword="null"/> will be returned if the operation failed due to access contention.</returns>
ValueTask<ConfigurationFileResponse> Write(string configurationRelativePath, ISystemIdentity systemIdentity, string previousHash, CancellationToken cancellationToken);
}
}
@@ -202,8 +202,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
protected sealed override ISessionController GetActiveController() => Server;
/// <inheritdoc />
protected override async Task InitController(
Task eventTask,
protected override async ValueTask InitController(
ValueTask eventTask,
ReattachInformation reattachInfo,
CancellationToken cancellationToken)
{
@@ -13,6 +13,7 @@ using Serilog.Context;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Internal;
using Tgstation.Server.Api.Rights;
using Tgstation.Server.Common.Extensions;
using Tgstation.Server.Host.Components.Chat;
using Tgstation.Server.Host.Components.Deployment;
using Tgstation.Server.Host.Components.Deployment.Remote;
@@ -452,7 +453,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
/// <inheritdoc />
async Task IEventConsumer.HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
async ValueTask IEventConsumer.HandleEvent(EventType eventType, IEnumerable<string> parameters, bool deploymentPipeline, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(parameters);
@@ -478,7 +479,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="reattachInfo"><see cref="ReattachInformation"/> to use, if any.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected abstract Task InitController(Task eventTask, ReattachInformation reattachInfo, CancellationToken cancellationToken);
protected abstract ValueTask InitController(ValueTask eventTask, ReattachInformation reattachInfo, CancellationToken cancellationToken);
/// <summary>
/// Launches the watchdog.
@@ -488,8 +489,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="announceFailure">If launch failure should be announced to chat by this function.</param>
/// <param name="reattachInfo"><see cref="ReattachInformation"/> to use, if any.</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 LaunchNoLock(
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
protected async ValueTask LaunchNoLock(
bool startMonitor,
bool announce,
bool announceFailure,
@@ -504,7 +505,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
throw new JobException(ErrorCode.WatchdogCompileJobCorrupted);
// this is necessary, the monitor could be in it's sleep loop trying to restart, if so cancel THAT monitor and start our own with blackjack and hookers
var eventTask = Task.CompletedTask;
var eventTask = ValueTask.CompletedTask;
if (announce)
{
Chat.QueueWatchdogMessage(
@@ -532,7 +533,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
{
Logger.LogWarning(e, "Failed to start watchdog!");
var originalChatTask = eventTask;
async Task ChainEventTaskWithErrorMessage()
async ValueTask ChainEventTaskWithErrorMessage()
{
await originalChatTask;
if (announceFailure)
@@ -606,11 +607,11 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
/// <summary>
/// Call from <see cref="InitController(Task, ReattachInformation, CancellationToken)"/> when a reattach operation fails to attempt a fresh start.
/// Call from <see cref="InitController(ValueTask, ReattachInformation, CancellationToken)"/> when a reattach operation fails to attempt a fresh start.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
protected async Task ReattachFailure(CancellationToken cancellationToken)
protected async ValueTask ReattachFailure(CancellationToken cancellationToken)
{
// we lost the server, just restart entirely
// DCT: Operation must always run
@@ -619,7 +620,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
Logger.LogWarning(FailReattachMessage);
Chat.QueueWatchdogMessage(FailReattachMessage);
await InitController(Task.CompletedTask, null, cancellationToken);
await InitController(ValueTask.CompletedTask, null, cancellationToken);
}
/// <summary>
@@ -696,12 +697,12 @@ 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 HandleEventImpl(EventType eventType, IEnumerable<string> parameters, bool relayToSession, CancellationToken cancellationToken)
protected async ValueTask HandleEventImpl(EventType eventType, IEnumerable<string> parameters, bool relayToSession, CancellationToken cancellationToken)
{
try
{
var sessionEventTask = relayToSession ? ((IEventConsumer)this).HandleEvent(eventType, parameters, false, cancellationToken) : Task.CompletedTask;
await Task.WhenAll(
var sessionEventTask = relayToSession ? ((IEventConsumer)this).HandleEvent(eventType, parameters, false, cancellationToken) : ValueTask.CompletedTask;
await ValueTaskExtensions.WhenAll(
eventConsumer.HandleEvent(eventType, parameters, false, cancellationToken),
sessionEventTask);
}
@@ -46,7 +46,7 @@ namespace Tgstation.Server.Host.Utils.GitHub
}
/// <inheritdoc />
public async Task<string> CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken)
public async ValueTask<string> CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(oAuthConfiguration);
@@ -71,7 +71,7 @@ namespace Tgstation.Server.Host.Utils.GitHub
}
/// <inheritdoc />
public async Task<Dictionary<Version, Release>> GetTgsReleases(CancellationToken cancellationToken)
public async ValueTask<Dictionary<Version, Release>> GetTgsReleases(CancellationToken cancellationToken)
{
logger.LogTrace("GetTgsReleases");
var allReleases = await gitHubClient
@@ -116,7 +116,7 @@ namespace Tgstation.Server.Host.Utils.GitHub
}
/// <inheritdoc />
public async Task<Uri> GetUpdatesRepositoryUrl(CancellationToken cancellationToken)
public async ValueTask<Uri> GetUpdatesRepositoryUrl(CancellationToken cancellationToken)
{
logger.LogTrace("GetUpdatesRepositoryUrl");
var repository = await gitHubClient
@@ -131,7 +131,7 @@ namespace Tgstation.Server.Host.Utils.GitHub
}
/// <inheritdoc />
public async Task<int> GetCurrentUserId(CancellationToken cancellationToken)
public async ValueTask<int> GetCurrentUserId(CancellationToken cancellationToken)
{
logger.LogTrace("CreateOAuthAccessToken");
@@ -162,7 +162,7 @@ namespace Tgstation.Server.Host.Utils.GitHub
}
/// <inheritdoc />
public async Task<long> GetRepositoryId(string repoOwner, string repoName, CancellationToken cancellationToken)
public async ValueTask<long> GetRepositoryId(string repoOwner, string repoName, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(repoOwner);
@@ -181,7 +181,7 @@ namespace Tgstation.Server.Host.Utils.GitHub
}
/// <inheritdoc />
public async Task<int> CreateDeployment(NewDeployment newDeployment, string repoOwner, string repoName, CancellationToken cancellationToken)
public async ValueTask<int> CreateDeployment(NewDeployment newDeployment, string repoOwner, string repoName, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(newDeployment);
@@ -28,8 +28,8 @@ namespace Tgstation.Server.Host.Utils.GitHub
/// <param name="repoOwner">The owner of the target repository.</param>
/// <param name="repoName">The name of the target repository.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the new deployment's ID.</returns>
Task<int> CreateDeployment(NewDeployment newDeployment, string repoOwner, string repoName, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the new deployment's ID.</returns>
ValueTask<int> CreateDeployment(NewDeployment newDeployment, string repoOwner, string repoName, CancellationToken cancellationToken);
/// <summary>
/// Create a <paramref name="newDeploymentStatus"/> on a target deployment.
@@ -18,16 +18,16 @@ namespace Tgstation.Server.Host.Utils.GitHub
/// Gets the <see cref="Uri"/> of the repository designated as the updates repository.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Uri"/> of the designated updates repository.</returns>
Task<Uri> GetUpdatesRepositoryUrl(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="Uri"/> of the designated updates repository.</returns>
ValueTask<Uri> GetUpdatesRepositoryUrl(CancellationToken cancellationToken);
/// <summary>
/// Get all valid TGS <see cref="Release"/>s from the configured update source.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="Dictionary{TKey, TValue}"/> of TGS <see cref="Release"/>s keyed by their <see cref="Version"/>.</returns>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="Dictionary{TKey, TValue}"/> of TGS <see cref="Release"/>s keyed by their <see cref="Version"/>.</returns>
/// <remarks>GitHub has been known to return incomplete results from the API with this call.</remarks>
Task<Dictionary<Version, Release>> GetTgsReleases(CancellationToken cancellationToken);
ValueTask<Dictionary<Version, Release>> GetTgsReleases(CancellationToken cancellationToken);
/// <summary>
/// Attempt to get an OAuth token from a given <paramref name="code"/>.
@@ -35,8 +35,8 @@ namespace Tgstation.Server.Host.Utils.GitHub
/// <param name="oAuthConfiguration">The <see cref="OAuthConfiguration"/>. Must have <see cref="OAuthConfiguration.RedirectUrl"/>, <see cref="OAuthConfigurationBase.ClientId"/> and <see cref="OAuthConfigurationBase.ClientSecret"/> set.</param>
/// <param name="code">The OAuth response code.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="string"/> representing the returned OAuth code from GitHub on success, <see langword="null"/> otherwise.</returns>
Task<string> CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in a <see cref="string"/> representing the returned OAuth code from GitHub on success, <see langword="null"/> otherwise.</returns>
ValueTask<string> CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken);
/// <summary>
/// Get a target repostiory's ID.
@@ -44,15 +44,15 @@ namespace Tgstation.Server.Host.Utils.GitHub
/// <param name="repoOwner">The owner of the target repository.</param>
/// <param name="repoName">The name of the target repository.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the target repository's ID.</returns>
Task<long> GetRepositoryId(string repoOwner, string repoName, CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the target repository's ID.</returns>
ValueTask<long> GetRepositoryId(string repoOwner, string repoName, CancellationToken cancellationToken);
/// <summary>
/// Get the current user's ID.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in the current user's ID.</returns>
Task<int> GetCurrentUserId(CancellationToken cancellationToken);
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the current user's ID.</returns>
ValueTask<int> GetCurrentUserId(CancellationToken cancellationToken);
/// <summary>
/// Get a given <paramref name="pullRequestNumber"/>.
@@ -77,10 +77,10 @@ namespace Tgstation.Server.Tests.Live
return Task.CompletedTask;
}
public Task<int> CreateDeployment(NewDeployment newDeployment, string repoOwner, string repoName, CancellationToken cancellationToken)
public ValueTask<int> CreateDeployment(NewDeployment newDeployment, string repoOwner, string repoName, CancellationToken cancellationToken)
{
logger.LogTrace("CreateDeployment");
return Task.FromResult(new Random().Next()); ;
return ValueTask.FromResult(new Random().Next()); ;
}
public Task CreateDeploymentStatus(NewDeploymentStatus newDeploymentStatus, string repoOwner, string repoName, int deploymentId, CancellationToken cancellationToken)
@@ -95,28 +95,28 @@ namespace Tgstation.Server.Tests.Live
return Task.CompletedTask;
}
public Task<string> CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken)
public ValueTask<string> CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken)
{
logger.LogTrace("CreateOAuthAccessToken");
return Task.FromResult(cryptographySuite.GetSecureString());
return ValueTask.FromResult(cryptographySuite.GetSecureString());
}
public Task<int> GetCurrentUserId(CancellationToken cancellationToken)
public ValueTask<int> GetCurrentUserId(CancellationToken cancellationToken)
{
logger.LogTrace("GetCurrentUserId");
return Task.FromResult(new Random().Next());
return ValueTask.FromResult(new Random().Next());
}
public Task<long> GetRepositoryId(string repoOwner, string repoName, CancellationToken cancellationToken)
public ValueTask<long> GetRepositoryId(string repoOwner, string repoName, CancellationToken cancellationToken)
{
logger.LogTrace("GetRepositoryId");
return Task.FromResult(new Random().NextInt64());
return ValueTask.FromResult(new Random().NextInt64());
}
public Task<Uri> GetUpdatesRepositoryUrl(CancellationToken cancellationToken)
public ValueTask<Uri> GetUpdatesRepositoryUrl(CancellationToken cancellationToken)
{
logger.LogTrace("GetUpdatesRepositoryUrl");
return Task.FromResult(new Uri("https://github.com/tgstation/tgstation-server"));
return ValueTask.FromResult(new Uri("https://github.com/tgstation/tgstation-server"));
}
public Task<PullRequest> GetPullRequest(string repoOwner, string repoName, int pullRequestNumber, CancellationToken cancellationToken)
@@ -125,10 +125,10 @@ namespace Tgstation.Server.Tests.Live
return Task.FromResult(testPr);
}
public Task<Dictionary<Version, Release>> GetTgsReleases(CancellationToken cancellationToken)
public ValueTask<Dictionary<Version, Release>> GetTgsReleases(CancellationToken cancellationToken)
{
logger.LogTrace("GetTgsReleases");
return Task.FromResult(releasesDictionary);
return ValueTask.FromResult(releasesDictionary);
}
}
}