diff --git a/docs/API.dox b/docs/API.dox index 5361caf7db..af9deb1ebe 100644 --- a/docs/API.dox +++ b/docs/API.dox @@ -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 diff --git a/src/Tgstation.Server.Client/Components/IJobsClient.cs b/src/Tgstation.Server.Client/Components/IJobsClient.cs index d019618763..c59dc7a8ba 100644 --- a/src/Tgstation.Server.Client/Components/IJobsClient.cs +++ b/src/Tgstation.Server.Client/Components/IJobsClient.cs @@ -18,13 +18,20 @@ namespace Tgstation.Server.Client.Components /// A resulting in a of the s in the Task> List(CancellationToken cancellationToken); + /// + /// List the active s in the + /// + /// The for the operation + /// A resulting in a of the active s in the + Task> ListActive(CancellationToken cancellationToken); + /// /// Get a /// /// The to get /// The for the operation /// A resulting in the - Task Read(Job job, CancellationToken cancellationToken); + Task GetId(Job job, CancellationToken cancellationToken); /// /// Cancels a diff --git a/src/Tgstation.Server.Client/Components/JobsClient.cs b/src/Tgstation.Server.Client/Components/JobsClient.cs index 35453ab6c6..7f9bf1cfa5 100644 --- a/src/Tgstation.Server.Client/Components/JobsClient.cs +++ b/src/Tgstation.Server.Client/Components/JobsClient.cs @@ -37,7 +37,10 @@ namespace Tgstation.Server.Client.Components public Task> List(CancellationToken cancellationToken) => apiClient.Read>(Routes.List(Routes.Jobs), instance.Id, cancellationToken); /// - public Task Read(Job job, CancellationToken cancellationToken) => apiClient.Read(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id, cancellationToken); + public Task> ListActive(CancellationToken cancellationToken) => apiClient.Read>(Routes.Jobs, instance.Id, cancellationToken); + + /// + public Task GetId(Job job, CancellationToken cancellationToken) => apiClient.Read(Routes.SetID(Routes.Jobs, job?.Id ?? throw new ArgumentNullException(nameof(job))), instance.Id, cancellationToken); /// public async Task CreateTaskFromJob(Job job, TimeSpan requeryRate, Action 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); diff --git a/src/Tgstation.Server.Host/Controllers/JobController.cs b/src/Tgstation.Server.Host/Controllers/JobController.cs index b48033ef4e..07c54687cc 100644 --- a/src/Tgstation.Server.Host/Controllers/JobController.cs +++ b/src/Tgstation.Server.Host/Controllers/JobController.cs @@ -40,10 +40,8 @@ namespace Tgstation.Server.Host.Controllers [TgsAuthorize] public override async Task 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())); } ///