Scope

  • Use Case:
    • Consider the situation where a a job chain should start a successor job chain on specific days of month only.
  • Solution Outline:
    • A single job is added to the calling job chain that will:
      • check the day of month for the currently executed order and add an order to a second job chain in case of matching days of month.
    • The solution works persistently across a restart of JobScheduler Master.
    • The solution considers fail-over in a JobScheduler Master Backup Cluster.

Solution

  • Download start_job_chain_on_date_condition.zip
  • Extract the archive to the ./config/live folder of your JobScheduler Master installation.
  • The archive extracts the files to a folder with the name start_job_chain_on_date_condition. 
  • You can store the sample files in any folder as you like, however, please adjust job parameters as explained below.

Pattern


Implementation

Components

  • The solution implements a job with the name start_job_chain_on_day_of_month that can be added to any job chain.
  • This job is parameterized to check the start date of the current order (not necessarily the current date) and to compare the specified day of month. 
  • This job can be run multiple times within the same period (day) and will add an order only for the first execution of this job if not otherwise specified.
    • The job makes use of a database table with two columns NAME and VALUE to persistently store its last execution date and number of recent executions in two records with the following values for the NAME column:
      • <job-chain-path>.last_order_start_time
      • <job-chain-path>.last_order_num
    • where <job-chain-path> is the full path of the job chain in which this job is executed.

Parameterization

The job makes use of the following parameters:

  • Mandatory Parameters
    • job_chain
      • The full path of the job chain to which an order is added. No order id is specified, therefore, should an order with the same id exist with the target job chain then the target order will be replaced.
    • day_of_month
      • The number of the day in the current month on which an order is added to the target job chain.
    • hibernate_file
      • The full path of the hibernate file that specifies the database connection.
      • Consider location of the hibernate file when using this job with JobScheduler Master or Agents.
  • Optional Parameters
    • max_order_num (default: 1)
      • The max. number of orders that are added by this job in a  period. Each execution of the job will add only one order. Subsequent executions within the same period will add additional orders up to the specified maximum.
    • table_name (default: CUSTOM_VARIABLES)
      • The job creates a table with the specified name in the database that is determined by the hibernate_file parameter. An existing table with the same name is reused.
      • The job automatically creates a table with this name and will add records respectively.
    • at (default: now)
      • Specifies the point in time when the order should start in the target job chain. By default the order starts immediately.
      • Relative values can be specified e.g. by use of now+30 to start the order 30s later or by now+13:30 to start the order at 1.30 pm.
      • Absolute values can be specified including date and time.
      • For details about date/time formats see the at attribute.

Usage

  • Add an Ad Hoc order to the job chain start_job_chain_on_day_of_month.
    • During its first run the job will create a database table in order to store job run values persistently.
    • The job will add an order to job chain job_chain2.
  • Subsequent runs of this job will not result in orders being added to job chain job_chain2.
    • You can modify the max_order_num parameter to specify the maximum number of orders that are added by this job to the target job chain.

 

  • No labels