K Khan
Oct 14, 2014
  6813
(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
Optimizely's personalized product recommendations on Product Details Page (PDP) 

With the rise of AI and its integration into online shopping, personalization has become the cornerstone of an enhanced customer experience....

Hetaxi | Sep 20, 2024

keep special characters in URL

When creating a page, the default URL segment validation automatically replaces special characters with their standard equivalents (e.g., "ä" is...

K Khan | Sep 19, 2024

Streamlining Marketing Success: The Benefits for Optimizely One with Perficient

As an Optimizely expert, I eagerly anticipate this time of year due to the exciting Optimizely events happening worldwide. These include Opticon, t...

Alex Harris - Perficient | Sep 17, 2024 | Syndicated blog

Creating an Optimizely Addon - Packaging for NuGet

In   Part One   and   Part Two   of this series; I covered topics from having a great idea, solution structure, extending the menus and adding...

Mark Stott | Sep 16, 2024

Optimizely CMS and weekly updates

Learn how reporting bugs in Optimizely CMS not only helps improve the platform but also benefits you and the entire user community.

Tomas Hensrud Gulla | Sep 12, 2024 | Syndicated blog

Introduce the ablility to select then delete items manually on FIND UI

In FIND 16.3.0 we introduce an ability to select items and delete them manually, it will helps you to delete unexpected items from the UI without a...

Manh Nguyen | Sep 12, 2024