Try our conversational search powered by Generative AI!

Setting interval for new job


I have a scheduled job for EPiServer, I can see it in Admin mode can run it, etc. I general everything is ok with the job itself. But I would like to provide default scheduling so that the user does not have to configure it manually. However, until I check the "Active" checkbox on job configuration  page the job is not listed in ScheduledJob.List() collection. How to I make the job appear on this list programatically (from code)? I thought that maybe instantiating ScheduledJob class is the way to go, but the constructors require some weird parameters (date of last and next execution? isStatic?).

Sep 28, 2012 12:34

You can obtain a ScheduledJob instance through the static overload, passing in your type and assembly. When you have an instance you should be able to modify its parameters, and save it.

Something like this should set a schedule of daily at midnight, (note this is untested):

            var yourJobType = typeof(YourScheduledJob);
            var assemblyName = Assembly.GetAssembly(yourJobType).GetName().Name;

            var yourJob = ScheduledJob.Load("Execute", yourJobType.FullName, assemblyName);

            yourJob.IsEnabled = true;
            yourJob.IntervalType = ScheduledIntervalType.Days;
            yourJob.NextExecution = DateTime.Today.AddDays(1);

Hope this works for you.

Oct 02, 2012 14:22
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.