SaaS CMS has officially launched! Learn more now.

IScheduledJobExecutor - only for manual execution?



I stumbled upon the interface IScheduledJobExecutor (EPiServer.Scheduler.IScheduledJobExecutor).

Is this interface only for manual execution of scheduled jobs?

Would it be possible to mimic the behavior of scheduled jobs in admin mode using IScheduledJobExecutor? For example creating a ScheduledJob and then scheduling it in an InitializableModule using IScheduledJobExecutor?

Jun 28, 2019 15:04

If you want to run jobs as admin when running from the scheulder you just need to have

// This block allows for a scheduled job to perform content repository updates when ran on a schedule,
            // If the scheduled job is exectued manually, this block is ignored
            if (HttpContext.Current == null)
                var imponationService = ServiceLocator.Current.GetInstance<IUserImpersonation>();
                var identity = imponationService.CreatePrincipal("admin");

                PrincipalInfo.CurrentPrincipal = identity;

Replacing admin in your code with whichever user you want to run as.

Jun 28, 2019 16:40

Thanks for the reply, Scott!

I was probably unclear but what I wanted to know is if there's a way to use IScheduledJobExecutor to run a job async and still get the admin mode user interface for the job (

I've been at this before but when you use the attribute ScheduledPlugIn to decorate a class, apparently you can only run the job synchronously. Microsoft has some internal helper class for running sync code async, but somehow it doesn't feel right. With the IScheduledJobExecutor you should be able to run a job async.

Jul 01, 2019 8:07

What are you trying to achieve from doing this?. We have some large jobs running which we've had Episerver and the DXC move to a separate instance which they'll do if you're worried about the processing of the job impacting the main website thread?

Jul 01, 2019 10:49

Also DXC support Azure WebJobs now

Jul 01, 2019 10:49

Ok. We're running our sites on-prem.

I'm just afraid that running a lot of async code in our scheduled jobs might affect the performance of the site and the web server as a whole.

Jul 01, 2019 10:59

Yes it can do that's why on the DXC there's that option but if you're running on premise what I would do is just set up another IIS site. You can sent the main website to have enableScheduler=”false” so that the jobs don't run there and then true on the new instance. Then the second instance become a scheduler website where you can be sure there's no impact, that's all they do in the DXC article I linked to. This then avoids any performance issues, you can even put it on a separate IIS server if you like.

Jul 01, 2019 11:02
* 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.