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

Set next execution time of ScheduledPlugIn at app start

Vote:
 

I have a ScheduledPlugIn that I'd like to run the next minute (at the latest) after each time the application starts.

http://world.episerver.com/Blogs/Lee-Crowe/Dates/2012/4/EPiServer-Schedule-Job-Maintenance-EPiServer-CMS-6/

That post has all I need but isn't there a way to save a scheduled job item than to use a SqlCommand?

#60648
Aug 21, 2012 9:30
Vote:
 

Is there any problem with calling the static Execute method of the class directly from application start? Otherwise that might be an option

#60650
Aug 21, 2012 10:43
Vote:
 

If it's possible to call Execute async to not slow down app start it could be an option.

The job takes quite a while to finish so I'd like the scheduler to run it. I'd also prefer if the entered interval uses the app start time for later executions.

#60657
Aug 21, 2012 13:07
Vote:
 

Either start a new thread and do it asynch or use the built in scheduler then I guess. To use the built in scheduler you can use something similar to this code in application start up... (using EPiServer.DataAbstraction)

 private void InitializeScheduledJob()
        {
            const string fullTypeName = "PROJECT.Web.Plugins.ScheduledJobs.CLASS_NAME_OF_JOB";
            const string assemblyName = "PROJECT.Web";
            const string methodName = "Execute";
            var now = DateTime.Now;
            var job = ScheduledJob.Load(methodName, fullTypeName, assemblyName);
            job.NextExecution = now.AddMinutes(1);
            job.IntervalLength = 1;
            job.IntervalType = ScheduledIntervalType.Days;
            job.Save();
        }

Hope this helps

#60658
Aug 21, 2012 14:02
Vote:
 

Looks like exactly what I need. Will try out later this week. Thanks!

#60661
Aug 21, 2012 14:25
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.