mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-14 04:13:18 +02:00
Option to disable/enable jobs
This commit is contained in:
parent
bf332717a5
commit
5921e524a9
@ -212,6 +212,7 @@ public class JobController(PgsqlContext context) : Controller
|
||||
return NotFound();
|
||||
|
||||
ret.RecurrenceMs = modifyJobRecord.RecurrenceMs ?? ret.RecurrenceMs;
|
||||
ret.Enabled = modifyJobRecord.Enabled ?? ret.Enabled;
|
||||
|
||||
context.SaveChanges();
|
||||
return new AcceptedResult(ret.JobId, ret);
|
||||
|
@ -1,3 +1,3 @@
|
||||
namespace API;
|
||||
|
||||
public record ModifyJobRecord(ulong? RecurrenceMs);
|
||||
public record ModifyJobRecord(ulong? RecurrenceMs, bool? Enabled);
|
@ -26,6 +26,7 @@ public abstract class Job
|
||||
[NotMapped]
|
||||
public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
||||
public JobState state { get; internal set; } = JobState.Waiting;
|
||||
public bool Enabled { get; internal set; } = true;
|
||||
|
||||
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())
|
||||
|
@ -69,18 +69,21 @@ public static class Tranga
|
||||
Log.Info(TRANGA);
|
||||
while (true)
|
||||
{
|
||||
List<Job> completedJobs = context.Jobs.Where(j => j.state >= JobState.Completed && j.state < JobState.Failed).ToList();
|
||||
List<Job> completedJobs = context.Jobs.Where(j => j.state >= JobState.Completed).ToList();
|
||||
foreach (Job job in completedJobs)
|
||||
if (job.RecurrenceMs <= 0)
|
||||
context.Jobs.Remove(job);
|
||||
else
|
||||
{
|
||||
if (job.state >= JobState.Failed)
|
||||
job.Enabled = false;
|
||||
else
|
||||
job.state = JobState.Waiting;
|
||||
job.LastExecution = DateTime.UtcNow;
|
||||
job.state = JobState.Waiting;
|
||||
context.Jobs.Update(job);
|
||||
}
|
||||
|
||||
List<Job> runJobs = context.Jobs.Where(j => j.state <= JobState.Running).ToList()
|
||||
List<Job> runJobs = context.Jobs.Where(j => j.state <= JobState.Running && j.Enabled == true).ToList()
|
||||
.Where(j => j.NextExecution < DateTime.UtcNow).ToList();
|
||||
foreach (Job job in runJobs)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user