Skip to content

Commit

Permalink
Merge pull request #1998 from tgstation/WrappingUp [RESTDeploy][Nuget…
Browse files Browse the repository at this point in the history
…Deploy]

Instance Start/Stop crons + Fixes
  • Loading branch information
Cyberboss authored Nov 3, 2024
2 parents bfd9d2e + 9f220cc commit 90c5666
Show file tree
Hide file tree
Showing 41 changed files with 5,217 additions and 169 deletions.
8 changes: 4 additions & 4 deletions build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<PropertyGroup>
<TgsCoreVersion>6.12.0</TgsCoreVersion>
<TgsConfigVersion>5.4.0</TgsConfigVersion>
<TgsRestVersion>10.11.0</TgsRestVersion>
<TgsRestVersion>10.12.0</TgsRestVersion>
<TgsGraphQLVersion>0.5.0</TgsGraphQLVersion>
<TgsCommonLibraryVersion>7.0.0</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>16.2.0</TgsApiLibraryVersion>
<TgsClientVersion>19.2.0</TgsClientVersion>
<TgsApiLibraryVersion>16.3.0</TgsApiLibraryVersion>
<TgsClientVersion>19.3.0</TgsClientVersion>
<TgsDmapiVersion>7.3.0</TgsDmapiVersion>
<TgsInteropVersion>5.10.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.5.0</TgsHostWatchdogVersion>
<TgsSwarmProtocolVersion>7.0.0</TgsSwarmProtocolVersion>
<TgsSwarmProtocolVersion>8.0.0</TgsSwarmProtocolVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
<TgsMigratorVersion>2.0.0</TgsMigratorVersion>
<TgsNugetNetFramework>netstandard2.0</TgsNugetNetFramework>
Expand Down
18 changes: 17 additions & 1 deletion src/Tgstation.Server.Api/Models/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,29 @@ public abstract class Instance : NamedEntity
/// </summary>
/// <remarks>Updates will not be triggered if the previous update is still running. Incompatible with <see cref="AutoUpdateInterval"/>.</remarks>
[Required]
[StringLength(Limits.MaximumStringLength)]
[StringLength(Limits.CronStringLength)]
public string? AutoUpdateCron { get; set; }

/// <summary>
/// The maximum number of chat bots the <see cref="Instance"/> may contain.
/// </summary>
[Required]
public ushort? ChatBotLimit { get; set; }

/// <summary>
/// A cron expression indicating when the game server should start. Must be a valid 6 part cron schedule (SECONDS MINUTES HOURS DAY/MONTH MONTH DAY/WEEK). Empty <see cref="string"/> disables.
/// </summary>
/// <remarks>This will have no effect if the game server is already running when it fires.</remarks>
[Required]
[StringLength(Limits.CronStringLength)]
public string? AutoStartCron { get; set; }

/// <summary>
/// A cron expression indicating when the game server should stop. Must be a valid 6 part cron schedule (SECONDS MINUTES HOURS DAY/MONTH MONTH DAY/WEEK). Empty <see cref="string"/> disables.
/// </summary>
/// <remarks>This will have no effect if the game server is not running when it fires.</remarks>
[Required]
[StringLength(Limits.CronStringLength)]
public string? AutoStopCron { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Tgstation.Server.Api/Models/Limits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public static class Limits
/// </summary>
public const int MaximumStringLength = 10000;

/// <summary>
/// Length limit for cron strings in fields.
/// </summary>
public const int CronStringLength = 1000;

/// <summary>
/// Length limit for <see cref="NamedEntity.Name"/>s.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Tgstation.Server.Api/Rights/InstanceManagerRights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,15 @@ public enum InstanceManagerRights : ulong
/// User can give themselves or their group full <see cref="InstancePermissionSetRights"/> on ALL instances.
/// </summary>
GrantPermissions = 1 << 10,

/// <summary>
/// User can change <see cref="Models.Instance.AutoStartCron"/>.
/// </summary>
SetAutoStart = 1 << 11,

/// <summary>
/// User can change <see cref="Models.Instance.AutoStopCron"/>.
/// </summary>
SetAutoStop = 1 << 12,
}
}
10 changes: 6 additions & 4 deletions src/Tgstation.Server.Host/Authority/AdministrationAuthority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ async Task<AdministrationResponse> CacheFactory()
{
Version? greatestVersion = null;
Uri? repoUrl = null;
var scopeCancellationToken = CancellationToken.None; // DCT: None available
try
{
var gitHubService = await gitHubServiceFactory.CreateService(cancellationToken);
var repositoryUrlTask = gitHubService.GetUpdatesRepositoryUrl(cancellationToken);
var releases = await gitHubService.GetTgsReleases(cancellationToken);
var gitHubService = await gitHubServiceFactory.CreateService(scopeCancellationToken);
var repositoryUrlTask = gitHubService.GetUpdatesRepositoryUrl(scopeCancellationToken);
var releases = await gitHubService.GetTgsReleases(scopeCancellationToken);

foreach (var kvp in releases)
{
Expand Down Expand Up @@ -139,7 +140,8 @@ async Task<AdministrationResponse> CacheFactory()
else
task = (Task<AdministrationResponse>)rawCacheObject!;

return new AuthorityResponse<AdministrationResponse>(await task);
var result = await task.WaitAsync(cancellationToken);
return new AuthorityResponse<AdministrationResponse>(result);
}
catch (RateLimitExceededException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ await Task.WhenAny(
Task.WhenAll(
disconnectTask,
listenTask ?? Task.CompletedTask),
AsyncDelayer.Delay(TimeSpan.FromSeconds(5), cancellationToken));
AsyncDelayer.Delay(TimeSpan.FromSeconds(5), cancellationToken).AsTask());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override async ValueTask StopServerProcess(
const int MaximumTerminationSeconds = 5;

logger.LogTrace("Attempting Robust.Server graceful exit (Timeout: {seconds}s)...", MaximumTerminationSeconds);
var timeout = asyncDelayer.Delay(TimeSpan.FromSeconds(MaximumTerminationSeconds), cancellationToken);
var timeout = asyncDelayer.Delay(TimeSpan.FromSeconds(MaximumTerminationSeconds), cancellationToken).AsTask();
var lifetime = process.Lifetime;
if (lifetime.IsCompleted)
logger.LogTrace("Robust.Server already exited");
Expand Down
14 changes: 14 additions & 0 deletions src/Tgstation.Server.Host/Components/IInstanceCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,19 @@ public interface IInstanceCore : ILatestCompileJobProvider, IRenameNotifyee
/// <param name="newCron">The new auto-update cron schedule.</param>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ScheduleAutoUpdate(uint newInterval, string? newCron);

/// <summary>
/// Change the server auto-start timing for the <see cref="IInstanceCore"/>.
/// </summary>
/// <param name="newCron">The new auto-start cron schedule.</param>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ScheduleServerStart(string? newCron);

/// <summary>
/// Change the server auto-stop timing for the <see cref="IInstanceCore"/>.
/// </summary>
/// <param name="newCron">The new auto-stop cron schedule.</param>
/// <returns>A <see cref="ValueTask"/> representing the running operation.</returns>
ValueTask ScheduleServerStop(string? newCron);
}
}
Loading

0 comments on commit 90c5666

Please sign in to comment.