tgstation-server 6.12.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(
77 .Jobs
78 .AsQueryable()
79 .Include(x => x.StartedBy)
80 .Include(x => x.CancelledBy)
81 .Include(x => x.Instance)
82 .Where(x => x.Instance!.Id == Instance.Id && !x.StoppedAt.HasValue)
83 .OrderByDescending(x => x.StartedAt))),
85 page,
88
102 () => ValueTask.FromResult(
105 .Jobs
106 .AsQueryable()
107 .Include(x => x.StartedBy)
108 .Include(x => x.CancelledBy)
109 .Include(x => x.Instance)
110 .Where(x => x.Instance!.Id == Instance.Id)
111 .OrderByDescending(x => x.StartedAt))),
113 page,
114 pageSize,
116
126 [HttpDelete("{id}")]
130 public async ValueTask<IActionResult> Delete(long id, CancellationToken cancellationToken)
131 {
132 // don't care if an instance post or not at this point
134 .Jobs
135 .AsQueryable()
136 .Include(x => x.StartedBy)
137 .Include(x => x.Instance)
138 .Where(x => x.Id == id && x.Instance!.Id == Instance.Id)
139 .FirstOrDefaultAsync(cancellationToken);
140 if (job == default)
141 return NotFound();
142
143 if (job.StoppedAt != null)
144 return Conflict(new ErrorMessageResponse(ErrorCode.JobStopped));
145
146 if (job.CancelRight.HasValue && job.CancelRightsType.HasValue && (AuthenticationContext.GetRight(job.CancelRightsType.Value) & job.CancelRight.Value) == 0)
147 return Forbid();
148
150 return updatedJob != null ? Accepted(updatedJob.ToApi()) : this.Gone();
151 }
152
161 [HttpGet("{id}")]
165 public async ValueTask<IActionResult> GetId(long id, CancellationToken cancellationToken)
166 {
168 .Jobs
169 .AsQueryable()
170 .Where(x => x.Id == id && x.Instance!.Id == Instance.Id)
171 .Include(x => x.StartedBy)
172 .Include(x => x.CancelledBy)
173 .Include(x => x.Instance)
174 .FirstOrDefaultAsync(cancellationToken);
175 if (job == default)
176 return NotFound();
177 var api = job.ToApi();
179 return Json(api);
180 }
181
192 }
193}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:13
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