fixed scheduler so that it does not set NextExecution until after the job has finished executing

This commit is contained in:
Shaun Walker 2020-07-23 11:38:20 -04:00
parent 62a6b5f28a
commit 3a6cde0e24

View File

@ -43,21 +43,26 @@ namespace Oqtane.Infrastructure
Job job = jobs.GetJobs().Where(item => item.JobType == jobType).FirstOrDefault();
if (job != null && job.IsEnabled && !job.IsExecuting)
{
// set next execution date
// get next execution date
DateTime NextExecution;
if (job.NextExecution == null)
{
if (job.StartDate != null)
{
job.NextExecution = job.StartDate;
NextExecution = job.StartDate.Value;
}
else
{
job.NextExecution = DateTime.UtcNow;
NextExecution = DateTime.UtcNow;
}
}
else
{
NextExecution = job.NextExecution.Value;
}
// determine if the job should be run
if (job.NextExecution <= DateTime.UtcNow && (job.EndDate == null || job.EndDate >= DateTime.UtcNow))
if (NextExecution <= DateTime.UtcNow && (job.EndDate == null || job.EndDate >= DateTime.UtcNow))
{
IJobLogRepository jobLogs = scope.ServiceProvider.GetRequiredService<IJobLogRepository>();
@ -91,7 +96,7 @@ namespace Oqtane.Infrastructure
jobLogs.UpdateJobLog(log);
// update the job
job.NextExecution = CalculateNextExecution(job.NextExecution.Value, job.Frequency, job.Interval);
job.NextExecution = CalculateNextExecution(NextExecution, job.Frequency, job.Interval);
job.IsExecuting = false;
jobs.UpdateJob(job);