2024-12-14 21:53:29 +01:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace API.Schema.Jobs;
|
|
|
|
|
|
|
|
|
|
[PrimaryKey("JobId")]
|
2024-12-16 18:55:52 +01:00
|
|
|
|
public abstract class Job
|
2024-12-14 21:53:29 +01:00
|
|
|
|
{
|
|
|
|
|
[MaxLength(64)]
|
|
|
|
|
public string JobId { get; init; }
|
|
|
|
|
|
|
|
|
|
[MaxLength(64)]
|
|
|
|
|
public string? ParentJobId { get; internal set; }
|
|
|
|
|
internal virtual Job ParentJob { get; }
|
|
|
|
|
|
|
|
|
|
[MaxLength(64)]
|
|
|
|
|
public string[]? DependsOnJobIds { get; init; }
|
|
|
|
|
public virtual Job[] DependsOnJobs { get; init; }
|
|
|
|
|
|
|
|
|
|
public JobType JobType { get; init; }
|
|
|
|
|
public ulong RecurrenceMs { get; set; }
|
|
|
|
|
public DateTime LastExecution { get; internal set; } = DateTime.UnixEpoch;
|
|
|
|
|
public DateTime NextExecution { get; internal set; }
|
|
|
|
|
public JobState state { get; internal set; } = JobState.Waiting;
|
|
|
|
|
|
|
|
|
|
public Job(string jobId, JobType jobType, ulong recurrenceMs, string? parentJobId = null,
|
|
|
|
|
string[]? dependsOnJobIds = null)
|
|
|
|
|
{
|
|
|
|
|
JobId = jobId;
|
|
|
|
|
ParentJobId = parentJobId;
|
|
|
|
|
DependsOnJobIds = dependsOnJobIds;
|
|
|
|
|
JobType = jobType;
|
|
|
|
|
RecurrenceMs = recurrenceMs;
|
|
|
|
|
NextExecution = LastExecution.AddMilliseconds(RecurrenceMs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract IEnumerable<Job> Run();
|
|
|
|
|
}
|