Views: 5860
Number of votes: 2
Average rating:

EPiServer Schedule Jobs (EPIServer 7.5+) FAQs

Schedule Job is a very useful feature to run some functionality periodically.

Q: Do we need scheduler services to run Schedule Jobs?


A: NO, scheduler service have been removed now. scheduled jobs are not executed in the Scheduler Service, but is executed on the site. In previous versions Scheduler service was responsible to keep track on when a job should execute and then make a request to the site to execute the job. This has now been chnaged so the site itself keeps track on when a job should execute and when that is time it calls the specific job.

Q: Will Schedule Job run if site is Down?


A: No, as site runs schedule job.

Q: How a scheduled job is called?


A: During initialization a check is performed against the database for which jobs that are about to be executed. A Timer will then be setup so a callback is executed when the job is to be run. Execute on the job will then be called on a worker thread.

Q: Is There any diffrence between runng the job manually or scheduling that?


A: scheduled jobs are not executed on a web request. Therfore under Schedule Job HttpContext.Current will be null, Code will not have any user rights during run. The manual trigger will cause the task to run with the currently logged in user’s account and with access to that HttpContext.

Q: Can we run job from a specific server in load balancing enviornment?


A: Yes. Each job will just run on one server at the time, it can be any server that perfroms the execution.By default all servers might run the job. How it works is that the first server that starts the specified job will mark in the database that it is executing the job and then the other servers will not start execution at that time. And then at next time it might be so that another server executes the job. If you want more control  it is possible to control which site that should execute scheduled jobs. This is achieved by setting attribute enableScheduler on configuration element /episerver/sites/site/siteSetting to true on the site that should execute the jobs and false on the other sites. In case several sites are configured to run scheduled jobs then each job will be scheduled for execution on all sites.

Q: How to run schedule job under a specific user?

A: Log on with the specified username
example PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("admin");

If Job Requires specific user permission
if(PrincipalInfo.CurrentPrincipal.Identity.Name == "*****")
{
   //ToDo
}

Disable permission checking for File
Set the BypassAccessCheck to true for IContent(EPiServer.dll)

Q: Can we pass input parameters in EPiServer Job


A: https://blog.mathiaskunto.com/2012/02/13/supplying-episerver-scheduled-jobs-with-parameters-through-admin-mode/

Q: How to implement a schedule job?


A: To implement a scheduled job you need to have a class marked with ScheduledPlugInAttribute. The recommendation is to inherit base class EPiServer.BaseLibrary.Scheduling.JobBase, if the class does not inherit the baseclass it needs to have a static method named "Execute" without parameters that return a string.
[ScheduledPlugIn(DisplayName = "Remove Unrelated Content Resources", LanguagePath = "/admin/databasejob/contentassetscleanupjob", HelpFile = "contentassetscleanupjob", DefaultEnabled = true, InitialTime = "1.1:0:0", IntervalLength = 1, IntervalType = ScheduledIntervalType.Weeks)]
    public class CleanUnusedAssetsFoldersJob : JobBase
    {
        protected override void OnStatusChanged(string statusMessage)
        {
            base.OnStatusChanged(statusMessage);
        }

        public override void Stop()
        {
            //ToDo
        }
 
        public override string Execute()
        {
            return "Job called"; 
        }
   }

Q: Can we get a list of schedule jobs programatically?


A: var plugIns = PlugInLocator.Search(new ScheduledPlugInAttribute()).ToList();

Oct 14, 2014

valdis
(By valdis, 10/20/2014 5:12:49 PM)

I've heard a nice plugin that shows all jobs in the grid in UI :)
https://github.com/valdisiljuconoks/TechFellow.ScheduledJobOverview

K Khan
(By K Khan , 10/20/2014 6:05:37 PM)

Q: Any nice plugin that shows all jobs in the grid in UI?
A: Yes, Valdis have done one for us :),
Thanks V

Please login to comment.