mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-17 16:57:54 +02:00
MangaConnectors do not have to return an Object with 6 Parameters.
Job-Start Logic readable and optimized More robust Database design
This commit is contained in:
@ -12,49 +12,50 @@ public abstract class Job
|
||||
[StringLength(64)]
|
||||
[Required]
|
||||
public string JobId { get; init; }
|
||||
[StringLength(64)]
|
||||
public string? ParentJobId { get; init; }
|
||||
[JsonIgnore]
|
||||
public Job? ParentJob { get; init; }
|
||||
[StringLength(64)]
|
||||
public ICollection<string>? DependsOnJobsIds { get; init; }
|
||||
[JsonIgnore]
|
||||
public ICollection<Job>? DependsOnJobs { get; init; }
|
||||
|
||||
[Required]
|
||||
public JobType JobType { get; init; }
|
||||
[Required]
|
||||
public ulong RecurrenceMs { get; set; }
|
||||
[Required]
|
||||
public DateTime LastExecution { get; internal set; } = DateTime.UnixEpoch;
|
||||
|
||||
[NotMapped]
|
||||
[Required]
|
||||
public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
||||
[Required]
|
||||
public JobState state { get; internal set; } = JobState.Waiting;
|
||||
[Required]
|
||||
public bool Enabled { get; internal set; } = true;
|
||||
|
||||
[NotMapped]
|
||||
[JsonIgnore]
|
||||
protected ILog Log { get; init; }
|
||||
|
||||
public Job(string jobId, JobType jobType, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
||||
: this(jobId, jobType, recurrenceMs, parentJob?.JobId, dependsOnJobs?.Select(j => j.JobId).ToList())
|
||||
[StringLength(64)] public string? ParentJobId { get; init; }
|
||||
[JsonIgnore] public Job? ParentJob { get; init; }
|
||||
[JsonIgnore] public ICollection<Job> DependsOnJobs { get; init; }
|
||||
|
||||
[Required] public JobType JobType { get; init; }
|
||||
|
||||
[Required] public ulong RecurrenceMs { get; set; }
|
||||
|
||||
[Required] public DateTime LastExecution { get; internal set; } = DateTime.UnixEpoch;
|
||||
|
||||
[NotMapped] [Required] public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
||||
[Required] public JobState state { get; internal set; } = JobState.FirstExecution;
|
||||
[Required] public bool Enabled { get; internal set; } = true;
|
||||
|
||||
[JsonIgnore] [NotMapped] internal bool IsCompleted => state is >= (JobState)128 and < (JobState)192;
|
||||
[JsonIgnore] [NotMapped] internal bool DependenciesFulfilled => DependsOnJobs.All(j => j.IsCompleted);
|
||||
|
||||
[NotMapped] [JsonIgnore] protected ILog Log { get; init; }
|
||||
|
||||
protected Job(string jobId, JobType jobType, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
||||
{
|
||||
this.JobId = jobId;
|
||||
this.JobType = jobType;
|
||||
this.RecurrenceMs = recurrenceMs;
|
||||
this.ParentJobId = parentJob?.JobId;
|
||||
this.ParentJob = parentJob;
|
||||
this.DependsOnJobs = dependsOnJobs;
|
||||
this.DependsOnJobs = dependsOnJobs ?? [];
|
||||
|
||||
this.Log = LogManager.GetLogger(this.GetType());
|
||||
}
|
||||
|
||||
public Job(string jobId, JobType jobType, ulong recurrenceMs, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||
/// <summary>
|
||||
/// EF ONLY!!!
|
||||
/// </summary>
|
||||
protected Job(string jobId, JobType jobType, ulong recurrenceMs, string? parentJobId)
|
||||
{
|
||||
Log = LogManager.GetLogger(GetType());
|
||||
JobId = jobId;
|
||||
ParentJobId = parentJobId;
|
||||
DependsOnJobsIds = dependsOnJobsIds;
|
||||
JobType = jobType;
|
||||
RecurrenceMs = recurrenceMs;
|
||||
this.JobId = jobId;
|
||||
this.JobType = jobType;
|
||||
this.RecurrenceMs = recurrenceMs;
|
||||
this.ParentJobId = parentJobId;
|
||||
this.DependsOnJobs = [];
|
||||
|
||||
this.Log = LogManager.GetLogger(this.GetType());
|
||||
}
|
||||
|
||||
public IEnumerable<Job> Run(IServiceProvider serviceProvider)
|
||||
|
Reference in New Issue
Block a user