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?
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.
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 (https://ibb.co/BzchPKY)?
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.
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? https://world.episerver.com/blogs/Sergey-Vorushilo/Dates/2017/12/scheduled-jobs-setup-in-dxc-service/
Also DXC support Azure WebJobs now
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.
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.