Parameters in a Sitecron Job – Sitecore Scheduler Module updated! version 1.1.6

So it’s been a while since I have been using this module in production for a while and very happy with it.  I made a few changes to help improve the usability.  In this iteration I added the option to pass in parameters into the job when it runs.  I have a nice surprise feature coming up shortly which will tie into this.

First I added a few checks and logging which helps us better manage the scheduled jobs. With the parameters, you can pass in parameters in which ever format as you like.  It’s the job’s responsibility to utilize the parameters being passed to it.

For instance you can pass in “Testing123” or “someval=1&who=me&whichone=first”, in the later we could use the Sitecore util and treat it similar to the Sitecore parameters.

I modified the Sitecron Job template to include a Parameters field. If you choose to add a value you could do so in the job(s) in /sitecore/system/Modules/Sitecron

I setup two jobs:


and Sitecron_116-1

Here is a sample test class which pulls in the parameters:

using Quartz;
using Sitecore.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SampleJob.Parameters
    public class TestParams : IJob
        public void Execute(IJobExecutionContext context)
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            string jobParams = dataMap.GetString("Parameters");

            Log.Info(string.Format("Instance {0} of TestParams Job - {4}Parameters: {1} {4}Fired at: {2} {4}Next Scheduled For:{3}"
, context.JobDetail.Key, jobParams, context.FireTimeUtc.Value.ToString("r")
, context.NextFireTimeUtc.Value.ToString("r"), Environment.NewLine), this);

Once the job executes you can see that it passes in the parameter values in these log entries:

DefaultQuartzScheduler_Worker-1 15:44:00 INFO  Instance DEFAULT.403e4e4c-2029-4311-ba12-7df4538a12ab of TestParams Job - 
Parameters: this is the parameters value 
Fired at: Mon, 03 Aug 2015 19:44:00 GMT 
Next Scheduled For:Mon, 03 Aug 2015 19:46:00 GMT

DefaultQuartzScheduler_Worker-2 15:45:00 INFO  Instance DEFAULT.12b63339-d791-42a2-a85b-a19f77b41db8 of TestParams Job - 
Parameters: print=1&target=me&group=first 
Fired at: Mon, 03 Aug 2015 19:45:00 GMT 
Next Scheduled For:Mon, 03 Aug 2015 19:48:00 GMT

Notice that you can output the execution time and the next scheduled execution time. This can be very useful.

Market Place:
For help with Cron Expressions you can use
If you need more information please do get in touch with me. I posted the update to the marketplace, I am waiting for the approval. Also I updated the GitHub.

2 thoughts on “Parameters in a Sitecron Job – Sitecore Scheduler Module updated! version 1.1.6”

  1. Thanks Akshay for building and sharing this module !! This is useful and we are planning to use this in our implementation.

    One nice feature addition would be to enable/disable a job from within Sitecore, as there will be scenarios when you want to temporarily stop running a job. I understand we can do this by changing the Cron expression. The challenge is that the person who is changing should remember to put back the right Cron expression to re-enable the job. So from an Operations standpoint, it would be a lot more easier to have a Checkbox to enable/disable the job from within Sitecore.

    For now, we have used the support for Parameters (enabled=1 or enabled=0) to handle this within our individual jobs.

  2. Thanks for the comment Jinto. Makes complete sense, I am adding some more functionality shortly, will update this aswell.

Leave a Reply

Your email address will not be published. Required fields are marked *