Create a Cron Using Cron ExpressionsAdmin Scope

Note: Ensure you have installed the required package to use this SDK method.

The example code snippet in this section will detail the manner you can use Cron Expressions to configure the schedule of your cron. Once you’ve configured the cron, you can pass it to the createCron() SDK method to create the required cron.

The jobScheduling reference used in the code snippets below is the component instance created to perform these operations.

Notes:
  • Learn more about Cron Expressions

  • It is advised you generate your cron expression using the Builder in the console and then copy the expression for your use case. This will ensure you avoid any unintentional errors.

  • In the following SDK, the cron has been configured using Cron Expressions, to submit a job to the job pool on 0Hrs 0Mins 0Secs on every 1st day of the week on the 1st month of every year. You can change this value as per your requirement by passing the relevant value to the cron_expression JSON key-value pair.

Parameters Used

You need to construct two JSON objects, one that provides the meta of the job that needs to be submitted and the other is to contain your cron’s meta that will schedule the submission of the job to the job pool.

The JSON attributes used in these two JSONs are provided in the following table:

JSON Object JSON Attributes Definition
job_meta job_name Mandatory parameter. Contains the name of the job that needs to be submitted to the job pool.
target_type Mandatory parameter. Contains the type of the job. (Function | Circuit | Webhook | AppSail).
target_name or target_id Mandatory parameter. Contains the name or ID of the target type. While it is mandatory to provide value for either of them, it is optional to provide values for both fields.
jobpool_name or jobpool_id Mandatory parameter. Contains the name or ID of the Job Pool. While it is mandatory to provide value for either of them, it is optional to provide values for both fields.
job_config
  • Optional parameter. The number of retries and the retry interval can be provided as a JSON key-value pair.
  • number_of_retries: The number of retries that need to be attempted.
  • retry_interval: The interval in which the retries need to occur.
expressionCron cron_name Mandatory parameter. To refer to your cron. Ensure you provide a unique name.
description Optional parameter. You can provide a description for your cron.
cron_status Mandatory parameter. Determines if the cron is enabled or not. Ensure it is set as 'true'.
cron_type Mandatory parameter. Determines the type of Cron. The value will need to provided as CronExpression to create crons using Cron Expressions.
cron_detail Mandatory parameter. The required details will be provided using cron expressions.
job_meta Mandatory parameter. Pass the jobMeta JSON object as value.

copy
// create function job meta
const jobMeta = {
  job_name: 'test_job', // set a name for the job
  target_type: 'Function', // set the target type as Function for function jobs
  target_name: 'target_function', // set the target function's name (optional) (either target_id or target_name is mandatory)
  // target_id: '123467890', // set the target function's ID (optional) (either target_id or target_name is mandatory)
  jobpool_name: 'test', // set the name of the function jobpool (optional) (either jobpool_name or jobpool_id is mandatory)
  // jobpool_id: '1234567890', // set the ID of the function jobpool (optional) (either jobpool_name or jobpool_id is mandatory)
  job_config: {
    number_of_retries: 2, // set the number of retries
    retry_interval: 15 * 60 // set the retry interval
  }, // set job config - job retries => 2 retries in 15 mins (optional)
  params: {
    arg1: 'test',
    arg2: 'job'
  } // set params to be passed to target function (optional)
};
// create expression cron details
const expressionCron = {
  cron_name: 'expression_cron', // set a name for the cron (unique)
  description: 'expression_cron', // set a description for the cron (optional)
  cron_status: true, // set the cron status as enabled
  cron_type: 'CronExpression', // set the cron type as Calendar for daily, monthly and yearly
  cron_expression: '0 0 * 1 1', // set the cron expression
  // timezone: 'America/Los_Angeles', // set the timezone (optional)
  cron_detail: {}, // set the cron details
  job_meta: jobMeta // set function job meta
};
// create expression cron 
const expressionCronDetails = await jobScheduling.CRON.createCron(expressionCron);
Note: We urge you to use this SDK to exclusively configure Dynamic Crons, and use the console's UI Builder to exclusively configure Pre-defined Crons.

Last Updated 2026-07-02 14:51:41 +0530 IST