mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-17 16:57:54 +02:00
Add API
This commit is contained in:
40
API/Schema/Jobs/Job.cs
Normal file
40
API/Schema/Jobs/Job.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Schema.Jobs;
|
||||
|
||||
[PrimaryKey("JobId")]
|
||||
public abstract class Job : APISerializable
|
||||
{
|
||||
[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();
|
||||
}
|
Reference in New Issue
Block a user