tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
JobController.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading;
4using System.Threading.Tasks;
5
6using Microsoft.AspNetCore.Mvc;
7using Microsoft.EntityFrameworkCore;
8using Microsoft.Extensions.Logging;
9
21
23{
27 [Route(Routes.Jobs)]
29 {
34
45 IDatabaseContext databaseContext,
46 IAuthenticationContext authenticationContext,
50 IApiHeadersProvider apiHeaders)
51 : base(
52 databaseContext,
53 authenticationContext,
54 logger,
56 apiHeaders)
57 {
59 }
60
69 [HttpGet]
74 () => ValueTask.FromResult<PaginatableResult<Job>?>(
77 .Jobs
78 .Include(x => x.StartedBy)
79 .Include(x => x.CancelledBy)
80 .Include(x => x.Instance)
81 .Where(x => x.Instance!.Id == Instance.Id && !x.StoppedAt.HasValue)
82 .OrderByDescending(x => x.StartedAt))),
84 page,
86 cancellationToken);
87
101 () => ValueTask.FromResult<PaginatableResult<Job>?>(
104 .Jobs
105 .Include(x => x.StartedBy)
106 .Include(x => x.CancelledBy)
107 .Include(x => x.Instance)
108 .Where(x => x.Instance!.Id == Instance.Id)
109 .OrderByDescending(x => x.StartedAt))),
111 page,
112 pageSize,
113 cancellationToken);
114
124 [HttpDelete("{id}")]
128 public async ValueTask<IActionResult> Delete(long id, CancellationToken cancellationToken)
129 {
130 // don't care if an instance post or not at this point
132 .Jobs
133 .Include(x => x.StartedBy)
134 .Include(x => x.Instance)
135 .Where(x => x.Id == id && x.Instance!.Id == Instance.Id)
136 .FirstOrDefaultAsync(cancellationToken);
137 if (job == default)
138 return NotFound();
139
140 if (job.StoppedAt != null)
141 return Conflict(new ErrorMessageResponse(ErrorCode.JobStopped));
142
143 if (job.CancelRight.HasValue && job.CancelRightsType.HasValue && (AuthenticationContext.GetRight(job.CancelRightsType.Value) & job.CancelRight.Value) == 0)
144 return Forbid();
145
147 return updatedJob != null ? Accepted(updatedJob.ToApi()) : this.Gone();
148 }
149
158 [HttpGet("{id}")]
162 public async ValueTask<IActionResult> GetId(long id, CancellationToken cancellationToken)
163 {
165 .Jobs
166 .Where(x => x.Id == id && x.Instance!.Id == Instance.Id)
167 .Include(x => x.StartedBy)
168 .Include(x => x.CancelledBy)
169 .Include(x => x.Instance)
170 .FirstOrDefaultAsync(cancellationToken);
171 if (job == default)
172 return NotFound();
173 var api = job.ToApi();
175 return Json(api);
176 }
177
188 }
189}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:14
Metadata about a server instance.
Definition Instance.cs:9
Represents an error message returned by the server.
Represents a long running job on the server. Model is read-only, updates attempt to cancel the job.
Definition JobResponse.cs:7
Routes to a server actions.
Definition Routes.cs:9
const string List
The postfix for list operations.
Definition Routes.cs:113
const string Jobs
The jobs controller.
Definition Routes.cs:103
new NotFoundObjectResult NotFound()
Generic 404 response.
readonly IInstanceManager instanceManager
The IInstanceManager for the ComponentInterfacingController.
ComponentInterfacingController for operations that require an instance.
JobController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, ILogger< JobController > logger, IInstanceManager instanceManager, IJobManager jobManager, IApiHeadersProvider apiHeaders)
Initializes a new instance of the JobController class.
ValueTask< IActionResult > List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
List all JobResponse for the instance in reverse creation order.
ValueTask AddJobProgressResponseTransformer(JobResponse jobResponse)
Supplements JobResponse PaginatedResponse<TModel>s with their JobResponse.Progress.
async ValueTask< IActionResult > Delete(long id, CancellationToken cancellationToken)
Cancel a running JobResponse.
readonly IJobManager jobManager
The IJobManager for the JobController.
async ValueTask< IActionResult > GetId(long id, CancellationToken cancellationToken)
Get a specific JobResponse.
ValueTask< IActionResult > Read([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
Get active JobResponses for the instance.
Backend abstract implementation of IDatabaseContext.
DbSet< Job > Jobs
The Jobs in the DatabaseContext.
ulong GetRight(RightsType rightsType)
Get the value of a given rightsType .The value of rightsType . Note that if InstancePermissionSet is ...
Manages the runtime of Jobs.
void SetJobProgress(JobResponse apiResponse)
Set the JobResponse.Progress and JobResponse.Stage for a given apiResponse .
ValueTask< Job?> CancelJob(Job job, User? user, bool blocking, CancellationToken cancellationToken)
Cancels a give job .
For creating and accessing authentication contexts.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12