November Happy Hour will be moved to Thursday December 5th.

Schedule job not starting automatically

Vote:
 

Hi!

I have an Initialization module programmatically setting a scheduled job to run after the initialization process. As per (https://marisks.net/2019/04/23/episerver-starting-scheduled-job-programmatically/).
This used to work in our project previously, however after upgrading to CMS12 and running this in the new sample Alloy site it has stopped working. The scheduled job does not start at all anymore.

private static void ScheduleRunNow(ScheduledJob job, IScheduledJobRepository scheduledJobRepository)
		{
			job.IntervalType = ScheduledIntervalType.None;
			job.IntervalLength = 0;
			job.IsEnabled = true;
			job.NextExecution = DateTime.Now.AddSeconds(10);
			scheduledJobRepository.Save(job);
		}

The job does get updated with the Next Execution time, it does not get enabled and it does not run when the time passes.

#279459
Apr 29, 2022 12:50
Vote:
 

This could be related to timing - when does your module run compared to CMS startup code. Can try to move your code to StartUp.cs and make sure it runs after CMS is initialized?

#280121
May 10, 2022 10:17
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.