Try our conversational search powered by Generative AI!

K Khan
Oct 14, 2014
  6774
(2 votes)

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

Comments

valdis
valdis Oct 20, 2014 03:12 PM

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

K Khan
K Khan Oct 20, 2014 04:05 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.
Latest blogs
Do not upgrade to EPiServer.CMS.Core 12.21.4 without reading this!

Todays update of EPiServer.CMS.Core 12.21.4 alters default sort order in an unexpected way, when you are working with muligple languages and have...

Tomas Hensrud Gulla | May 14, 2024 | Syndicated blog

Upgrade Optimizely CMS From v11 to v12

Why Upgrade? There are many improvements implemented in version 12, but most importantly is that the whole framework is migrated from .Net Framewor...

MilosR | May 13, 2024

Configured Commerce - Infrastructure Updates Ahoy!

I'm very happy to share an important milestone - we no longer have any customers in our legacy v1 environment!  This means that the Configured...

John McCarroll | May 10, 2024

A day in the life of an Optimizely Developer - Enabling Opti ID within your application

Hello and welcome to another instalment of A Day In The Life Of An Optimizely developer, in this blog post I will provide details on Optimizely's...

Graham Carr | May 9, 2024