Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InitializeScheduler should check that ExecuteExactlyAtDateTime is not in the past #4

Closed
Trisco opened this issue Feb 13, 2018 · 1 comment

Comments

@Trisco
Copy link

Trisco commented Feb 13, 2018

If you have Sitecron Jobs that use the "ExecuteExactlyAtDateTime", and that DateTimeUtc is set in the past, these jobs will trigger immediatelly whenever "InitializeScheduler" is executed, e.g. after application startup but also after every item.save of a Sitecron Job.

Possible scenarios:

  • when you have multiple sitecron jobs defined which you programmatically set the "ExecuteExactlyAtDateTime" (I want several jobs to run x minutes/hours/days after a certain event)
  • Item Package install (or TDS/Unicorn project) has a set of predefined Sitecron Jobs with "ExecuteExactlyAtDateTime" set in the past.

Every time you save a Sitecron Job, the scheduler reinitializes and all jobs with "ExecuteExactlyAtDateTime" in the past are triggered.

Imho ScheduleHelper.cs ln121 : the job should only be scheduled if the startDateTime is in the future:

`var startDateField = (DateField)i.Fields[SitecronConstants.FieldNames.ExecuteExactlyAtDateTime];
if (startDateField != null)
{
Log.Info(string.Format("Sitecron - Job Loaded - {0} using ExecuteExactlyAtDateTime: {1}", i.Name, i[SitecronConstants.FieldNames.ExecuteExactlyAtDateTime]), this);
DateTimeOffset startDateTime = new DateTimeOffset(startDateField.DateTime.ToUniversalTime());
if (startDateTime > DateTimeOffset.UtcNow)
{
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity(i.ID.ToString())
.StartAt(startDateTime)
.ForJob(jobDetail)
.Build();
scheduler.ScheduleJob(jobDetail, trigger);
}else{
Log.Info(string.Format("Sitecron - Job Not Loaded - ExecuteExactlyAtDateTime in the past: {0} ExecuteExactlyAtDateTime: {1} Cron Expression: {2}", i.Name, i[SitecronConstants.FieldNames.ExecuteExactlyAtDateTime], i[SitecronConstants.FieldNames.CronExpression]), this);

}
}`

@akshaysura
Copy link
Owner

Thank you for the detailed issue. This is being taken care of in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants