- Orders for job chains can be assigned calendars that specify the date for which an order should be executed, see JOC Cockpit - Calendar Management.
- Frequently such job chains are executed on a specific date, but should carry a business date parameter - handed over to scripts and executables - that specifies e.g. the previous day.
- In this situation the execution date is different from the business date and suggests some more complex scenarios:
- The business date might be specific for a calendar, let's assume Mon-Fri considering non-working days of a stock exchange in some country.
- The execution date could be specific for a company calendar in a different country that includes to execute jobs Mon-Thu excluding non-working days in that country or company.
- Therefore the order for a business date targeted for some Fri would be executed next Mon. Should this Mon meet a non-working day then the execution could be postponed to next Tue. As a result we face a non-deterministic number of days between the business date and the execution date.
- JobScheduler handles execution dates well, but does not know the distinction from a business date for which some job chain is executed. This article proposes a solution to this gap.
- Basically two calendars have to be used
- a calendar for business dates that are used to parameterize orders for job chains.
- a calendar for execution dates on which job chains are started.
- The solution includes to
- create a standalone job that creates an order for a job chain. The job runs on business dates and will create an order parameter for this date.
- create a job chain that is specified to run on execution dates, i.e. is based on its own calendar.
- As a consequence the following scenarios are covered;
- two orders for two business dates Thu and Fri are created. If Thu and Fri do not meet execution dates in the company calendar then both orders will wait in the target job chain to be executed e.g. next Mon, each order carrying its individual business date parameter.
- if one of the scheduled orders fails then this does not prevent other orders for other business dates from being executed.
- The below sample implementation is available for download: business_dates.zip
- Unzip the sample to your JobScheduler Master's
livefolder. This will create a
business_datesub-folder with the below job-related objects.
Standalone Job to create Orders for Business Dates
- The comments with the code should be self-explanatory,
- Consider that a
business_dateparameter is created that carries the current date.
- This sample does not make use of a calendar, but directly uses a start-time rule to run on Mon-Fri at 10am.
Job Chain to run on Execution Dates
The job chain
run_for_business_date references two jobs
- Consider use of the
on_errorattribute: in case of error for a job not the job will be stopped, but the order will be suspended. This allows subsequent orders to pass the job node independently from the execution result of a previous order.
- The second job
job2is not considered as it can implement any type of job execution.
Job to run on Execution Dates
job1 is implemented like this:
- This is the first job of the job chain. It simply echos it's job name and the
business_datejob parameter. Job syntax is presented for Windows, use
$SCHEDULER_PARAM_BUSINESS_DATEfor Unix environments.
- This sample does not make use of a calendar, but directly uses a start-time slot to allow execution on Mon-Thu. The start-time slot does not specify a point in time to start the job, but specifies a time-slot that prevents the job from running on any day outside of the time-slot (Mon-Thu). Therefore, if an orders arrives on Fri then this order will wait until Mon to be executed.
- The above examples are created without use of calendars in order to be compatible with JobScheduler releases before 1.12. Howevev, if you operate a more recent JobScheduler release then we encourage you to use Calendars from the JOC Cockpit that are much more flexible than start-time rules.
- The above example is not specific for a single job chain. Starting from the assumption that the standalone job
run_for_business_dateand the job chain carry the same name and are located in the same folder you can create copies of the standalone job to run for any job chain. The assumption of the standalone job is that the execution date should follow the business date (current date) by 24 hours.