Merge pull request #659 from sbwalker/master

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:39:19 -04:00 committed by GitHub
commit 05f67d6a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);