tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
Job.cs
Go to the documentation of this file.
1using System;
4using System.Linq;
5
9
11{
13#pragma warning disable CA1724 // naming conflict with gitlab package
14 public sealed class Job : Api.Models.Internal.Job, ILegacyApiTransformable<JobResponse>
15#pragma warning restore CA1724
16 {
20 [Required]
21 public User? StartedBy { get; set; }
22
26 public User? CancelledBy { get; set; }
27
31 [Required]
32 public Instance? Instance { get; set; }
33
43 public static Job Create<TRight>(JobCode code, User? startedBy, Api.Models.Instance instance, TRight cancelRight)
45 => new(
46 code,
48 instance,
49 RightsHelper.TypeToRight<TRight>(),
50 (ulong)(object)cancelRight);
51
59 public static Job Create(JobCode code, User? startedBy, Api.Models.Instance instance)
60 => new(
61 code,
63 instance,
64 null,
65 null);
66
70 [Obsolete("For use by EFCore only", true)]
71 public Job()
72 {
73 }
74
79 public Job(long id)
80 {
81 Id = id;
82 }
83
92 Job(JobCode code, User? startedBy, Api.Models.Instance instance, RightsType? cancelRightsType, ulong? cancelRight)
93 {
95 ArgumentNullException.ThrowIfNull(instance);
96 Instance = new Instance
97 {
98 Id = instance.Id ?? throw new InvalidOperationException("Instance associated with job does not have an Id!"),
99 };
101 .GetField(code.ToString())!
102 .GetCustomAttributes(false)
103 .OfType<DescriptionAttribute>()
104 .First()
105 .Description;
106 JobCode = code;
109 }
110
112 public JobResponse ToApi() => new()
113 {
114 Id = Id,
115 JobCode = this.Require(x => x.JobCode),
116 InstanceId = (Instance ?? throw new InvalidOperationException("Instance needs to be set!")).Require(x => x.Id),
126 StartedBy = (StartedBy ?? throw new InvalidOperationException("StartedBy needs to be set!")).CreateUserName(),
127 };
128 }
129}
virtual ? long Id
The ID of the entity.
Definition EntityId.cs:13
DateTimeOffset? StartedAt
When the Job was started.
Definition Job.cs:42
DateTimeOffset? StoppedAt
When the Job stopped.
Definition Job.cs:48
string? Description
English description of the Job.
Definition Job.cs:24
RightsType? CancelRightsType
The RightsType of CancelRight if it can be cancelled.
Definition Job.cs:60
ErrorCode? ErrorCode
The Models.ErrorCode associated with the Job if any.
Definition Job.cs:30
bool? Cancelled
If the Job was cancelled.
Definition Job.cs:54
ulong? CancelRight
The Rights required to cancel the Job.
Definition Job.cs:66
string? ExceptionDetails
Details of any exceptions caught during the Job.
Definition Job.cs:36
Represents a long running job on the server. Model is read-only, updates attempt to cancel the job.
Definition JobResponse.cs:7
UserName CreateUserName()
Create a copy of the UserName.
Represents an Api.Models.Instance in the database.
Definition Instance.cs:11
User? StartedBy
See JobResponse.StartedBy.
Definition Job.cs:21
static Job Create< TRight >(JobCode code, User? startedBy, Api.Models.Instance instance, TRight cancelRight)
Creates a new job for registering in the Jobs.IJobService.
Job(JobCode code, User? startedBy, Api.Models.Instance instance, RightsType? cancelRightsType, ulong? cancelRight)
Initializes a new instance of the Job class.
Definition Job.cs:92
Job(long id)
Initializes a new instance of the Job class.
Definition Job.cs:79
Job()
Initializes a new instance of the Job class.
Definition Job.cs:71
User? CancelledBy
See JobResponse.CancelledBy.
Definition Job.cs:26
static Job Create(JobCode code, User? startedBy, Api.Models.Instance instance)
Creates a new job for registering in the Jobs.IJobService.
Represents a host-side model that may be transformed into a TApiModel .
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12
JobCode
The different types of Response.JobResponse.
Definition JobCode.cs:9
@ Required
DMAPI validation must suceed for the deployment to succeed.
@ List
User may list files if the Models.Instance allows it.
RightsType
The type of rights a model uses.
Definition RightsType.cs:7