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

IScheduledJobExecutor - only for manual execution?

Vote:
 

Hi!

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?

#205114
Jun 28, 2019 15:04
Vote:
 

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.

#205126
Jun 28, 2019 16:40
Vote:
 

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.

#205152
Jul 01, 2019 8:07
Vote:
 

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/

#205158
Jul 01, 2019 10:49
Vote:
 

Also DXC support Azure WebJobs now

#205159
Jul 01, 2019 10:49
Vote:
 

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.

#205162
Jul 01, 2019 10:59
Vote:
 

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.

#205163
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.