mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-19 20:13:45 +01:00
GET on jobs now returns a list of active jobs
This commit is contained in:
+6
-2
@@ -212,11 +212,15 @@ Some requests return @ref Tgstation.Server.Api.Models.Job objects. These are lon
|
||||
|
||||
To list all jobs in an Instance use the following request
|
||||
|
||||
I GET "/Job" => Array of @ref Tgstation.Server.Api.Models.Job
|
||||
I GET "/Job/List" => Array of @ref Tgstation.Server.Api.Models.Job
|
||||
|
||||
Note that the response for this request will only have the @ref Tgstation.Server.Api.Models.Job.Id field populated
|
||||
|
||||
To get full details of a job use the following request:
|
||||
To get full details of _active_ jobs use the following request:
|
||||
|
||||
I GET "/Job" => Array of @ref Tgstation.Server.Api.Models.Job
|
||||
|
||||
To get full details of a specific job use the following request:
|
||||
|
||||
I GET "/Job/{JobId}" => @ref Tgstation.Server.Api.Models.Job
|
||||
|
||||
|
||||
@@ -18,13 +18,20 @@ namespace Tgstation.Server.Client.Components
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of the <see cref="Api.Models.Internal.Job.Id"/>s in the <see cref="Instance"/></returns>
|
||||
Task<IReadOnlyList<Job>> List(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// List the active <see cref="Job"/>s in the <see cref="Instance"/>
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in a <see cref="IReadOnlyList{T}"/> of the active <see cref="Job"/>s in the <see cref="Instance"/></returns>
|
||||
Task<IReadOnlyList<Job>> ListActive(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Get a <paramref name="job"/>
|
||||
/// </summary>
|
||||
/// <param name="job">The <see cref="Job"/> to get</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Job"/></returns>
|
||||
Task<Job> Read(Job job, CancellationToken cancellationToken);
|
||||
Task<Job> GetId(Job job, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels a <paramref name="job"/>
|
||||
|
||||
@@ -37,7 +37,10 @@ namespace Tgstation.Server.Client.Components
|
||||
public Task<IReadOnlyList<Job>> List(CancellationToken cancellationToken) => apiClient.Read<IReadOnlyList<Job>>(Routes.List(Routes.Jobs), instance.Id, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Job> Read(Job job, CancellationToken cancellationToken) => apiClient.Read<Job>(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id, cancellationToken);
|
||||
public Task<IReadOnlyList<Job>> ListActive(CancellationToken cancellationToken) => apiClient.Read<IReadOnlyList<Job>>(Routes.Jobs, instance.Id, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<Job> GetId(Job job, CancellationToken cancellationToken) => apiClient.Read<Job>(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id, cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Job> CreateTaskFromJob(Job job, TimeSpan requeryRate, Action<int> progressCallback, CancellationToken cancellationToken)
|
||||
@@ -51,7 +54,7 @@ namespace Tgstation.Server.Client.Components
|
||||
while (!job.StoppedAt.HasValue)
|
||||
{
|
||||
await Task.Delay(requeryRate, cancellationToken).ConfigureAwait(false);
|
||||
job = await Read(job, cancellationToken).ConfigureAwait(false);
|
||||
job = await GetId(job, cancellationToken).ConfigureAwait(false);
|
||||
if (job.Progress.HasValue && job.Progress != lastProgress)
|
||||
{
|
||||
progressCallback(job.Progress.Value);
|
||||
|
||||
@@ -40,10 +40,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
[TgsAuthorize]
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await DatabaseContext.Jobs.Where(x => x.Instance.Id == Instance.Id).OrderByDescending(x => x.StartedAt).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (result == null)
|
||||
return StatusCode((int)HttpStatusCode.Gone);
|
||||
return Json(result);
|
||||
var result = await DatabaseContext.Jobs.Where(x => x.Instance.Id == Instance.Id && !x.StoppedAt.HasValue).OrderByDescending(x => x.StartedAt).ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Json(result.Select(x => x.ToApi()));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user