mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-15 12:53:17 +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();
|
return NotFound();
|
||||||
|
|
||||||
ret.RecurrenceMs = modifyJobRecord.RecurrenceMs ?? ret.RecurrenceMs;
|
ret.RecurrenceMs = modifyJobRecord.RecurrenceMs ?? ret.RecurrenceMs;
|
||||||
|
ret.Enabled = modifyJobRecord.Enabled ?? ret.Enabled;
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return new AcceptedResult(ret.JobId, ret);
|
return new AcceptedResult(ret.JobId, ret);
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
namespace API;
|
namespace API;
|
||||||
|
|
||||||
public record ModifyJobRecord(ulong? RecurrenceMs);
|
public record ModifyJobRecord(ulong? RecurrenceMs, bool? Enabled);
|
@ -26,6 +26,7 @@ public abstract class Job
|
|||||||
[NotMapped]
|
[NotMapped]
|
||||||
public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
||||||
public JobState state { get; internal set; } = JobState.Waiting;
|
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)
|
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())
|
: this(jobId, jobType, recurrenceMs, parentJob?.JobId, dependsOnJobs?.Select(j => j.JobId).ToList())
|
||||||
|
@ -69,18 +69,21 @@ public static class Tranga
|
|||||||
Log.Info(TRANGA);
|
Log.Info(TRANGA);
|
||||||
while (true)
|
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)
|
foreach (Job job in completedJobs)
|
||||||
if (job.RecurrenceMs <= 0)
|
if (job.RecurrenceMs <= 0)
|
||||||
context.Jobs.Remove(job);
|
context.Jobs.Remove(job);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (job.state >= JobState.Failed)
|
||||||
|
job.Enabled = false;
|
||||||
|
else
|
||||||
|
job.state = JobState.Waiting;
|
||||||
job.LastExecution = DateTime.UtcNow;
|
job.LastExecution = DateTime.UtcNow;
|
||||||
job.state = JobState.Waiting;
|
|
||||||
context.Jobs.Update(job);
|
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();
|
.Where(j => j.NextExecution < DateTime.UtcNow).ToList();
|
||||||
foreach (Job job in runJobs)
|
foreach (Job job in runJobs)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user