A Dynamic Cron allows you to configure crons through code and schedule job submissions to the job pool dynamically durring runtime. In this help section, we are going to go over the steps required to schedule the submission of a job to the job pool using a Dynamic Cron.
Before you create a dynamic cron, depending on your job pool type, make sure the following components are configured and present in the Catalyst console:
Function Job Pool: The Job Function, if initialized through Catalyst CLI needs to be deployed to the Catalyst console, along with the code file containing the configuration of your dynamic cron.
Webhook Job Pool: Ensure the URL of the third-party URL is a valid one.
Circuit Job Pool: Ensure that the Circuit and its associated functions are created and present in the Catalyst console.
AppSail Job Pool: Ensure you have deployed your AppSail service to the catalyst console.
Points to remember when you create a Dynamic Cron:
Dynamic crons are ideally enabled and executed during run-time.
Dynamic crons can be created using the Builder, in the exact same way as a Pre-Defined Cron. However, this option is provided for you to
create and test the functionality of your dynamic crons in the Production environment.
Configure a Dynamic Cron
To create and configure a Dynamic cron:
Navigate to the Job Scheduling service section of the Catalyst console and click Start Exploring.
Access the cron component by clicking Cron under JOB EXECUTOR, and click the Create Cron button present in the Dynamic tab.
Click the SDK tab.
Note:
In this help documentation, we will only be going over the steps required to create a Dynamic Cron through code using Catalyst SDK.
You can refer this help documentation, where steps to create a Pre-Defined Cron using the Builder are explained. The Builder can be used in the exact same manner to create a Dynamic Cron.
The option to employ Dynamic Crons using the Builder is provided for you to
create and test the functionality of your dynamic crons in the Production environment.
Choose the type of code snippet you require to code your cron from the drop-down.
Configure a One-Time Dynamic Cron
One-Time Dynamic Cron
copy
// ONE TIME CRON => which will run after 60 minutes from the current time
ZCJobScheduling jobScheduling = ZCJobScheduling.getInstance(); // get job scheduling instance
// generate function job meta
ZCJobMetaDetail jobMeta = ZCJobBuilder.functionJobBuilder() // get function job builder
.setJobConfig(2, 15 * 60 * 1000L) // set job config - job retries => 2 retries in 15 mins (optional)
.setJobpoolName(“functions_job_pool”) // set the name of the function job pool (optional) (either jobpoolId or jobpoolName is mandatory)
// .setJobpoolId(1234567890L) // set the Id of the function job pool (optional) (either jobpoolId or jobpoolName is mandatory)
.setTargetName(“target_function”) // set target function’s name (optional) (either TargetName or TargetId is mandatory)
// .setTargetId(1234567890L) // set the target function’s Id (optional) (either TargetName or TargetId is mandatory)
.setParams(new JSONObject() {
{
put(“arg1”, “job”);
put(“arg2”, “test”);
}
}) // set params to be passed to target function (optional)
.setJobName(“job_name”) // set job name
.build(); // build job meta
// generate cron details
ZCCronDetails oneTimeCronDetails = ZCCronBuilder.zcOneTimeCronBuilder() // get one time cron builder
.setCronStatus(true) // set cron as enabled
.cronConfig(System.currentTimeMillis() + (60 * 1000 * 1000)) // set the execution time as UNIX timestamp
.setJobMeta(jobMeta) // set job meta (modify based on the job)
.setCronName(“one_time_cron”) // set cron name (unique)
.build(); // build cron details
// create one time cron
ZCCronDetails oneTimeCron = jobScheduling.cron.createCron(oneTimeCronDetails);
View more
One-Time Dynamic Cron
copy
// ONE TIME CRON => which will run after 60mins for the current time
// 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 functions’s Id (optional) (either target_id or target_name is mandatory)
jobpool_name: ’test’, // set the name of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
// jobpool_id: ‘1234567890’ // set the Id of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
job_config: {
number_of_retries: 2, // set the number of retries
retry_interval: 15 * 60 * 1000 + ’’ // 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 one time cron details
const oneTimeCron = {
cron_name: ‘one_time’, // set a name for the cron (unique)
cron_status: true, // set the cron status as enabled
cron_type: ‘OneTime’, // set the cron type as OneTime
cron_detail: {
time_of_execution: Date.now() + (60 * 1000 * 1000) + ’’ // set the execution time as UNIX timestamp
},
job_meta: jobMeta // set the function job meta
};
// create one time cron
const cronDetails = await jobScheduling.CRON.createCron(oneTimeCron);
View more
One-Time Dynamic Cron
copy
# ONE TIME CRON => which will run after 60mins for the current time
job_meta = {
‘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 functions’s Id (optional) (either target_id or target_name is mandatory)
‘jobpool_name’: ’test’, # set the name of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
# ‘jobpool_id’: ‘1234567890’ # set the Id of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
‘job_config’: {
’number_of_retries’: 2, # set the number of retries
‘retry_interval’: 15 * 60 * 1000 # 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 one time cron
one_time_cron_details = job_scheduling.CRON.create({
‘cron_name’: ‘one_time’, # set a name for the cron (unique)
‘cron_status’: True, # set the cron status as enabled
‘cron_type’: ‘OneTime’, # set the cron type as OneTime
‘cron_detail’: {
’time_of_execution’: int(time.time()) + (60 * 10 * 1000) # set the execution time as UNIX timestamp
},
‘job_meta’: job_meta # set the function job meta
})
View more
Configure a Recursive Dynamic Cron
Recursive Dynamic Cron
copy
ZCJobScheduling jobScheduling = ZCJobScheduling.getInstance(); // get job scheduling instance
// generate function job meta
ZCJobMetaDetail jobMeta = ZCJobBuilder.functionJobBuilder() // get function job builder
.setJobConfig(2, 15 * 60 * 1000L) // set job config - job retries => 2 retries in 15 mins (optional)
.setJobpoolName(“functions_job_pool”) // set the name of the function job pool (optional) (either jobpoolId or jobpoolName is mandatory)
// .setJobpoolId(1234567890L) // set the Id of the function job pool (optional) (either jobpoolId or jobpoolName is mandatory)
.setTargetName(“target_function”) // set target function’s name (optional) (either TargetName or TargetId is mandatory)
// .setTargetId(1234567890L) // set the target function’s Id (optional) (either TargetName or TargetId is mandatory)
.setParams(new JSONObject() {
{
put(“arg1”, “job”);
put(“arg2”, “test”);
}
}) // set params to be passed to target function (optional)
.setJobName(“job_name”) // set job name
.build(); // build job meta
// EVERY CRON => which will be run for every 2hrs 1min and 3sec
// generate cron details
ZCCronDetails everyCronDetails = ZCCronBuilder.zcEveryCronBuilder() // get every cron builder
.setCronStatus(true) // set cron as enabled
.setTime(2, 1, 3) // set the repetition interval
.setJobMeta(jobMeta) // set the job meta (modify based on the job)
.setCronName(“every_cron”) // set cron name (unique)
.build(); // build cron details
// create every cron
ZCCronDetails everyCron = jobScheduling.cron.createCron(everyCronDetails);
// DAILY CRON => which will be run on 0hrs 0mins and 0sec daily
// generate cron details
ZCCronDetails dailyCronDetails = ZCCronBuilder.zcDailyCronBuilder() // get daily cron builder
.setCronStatus(true) // set cron as enabled
.setTime(0, 0, 0) // set the time of the day during which the cron should be executed
.setJobMeta(jobMeta) // set the job meta (modify based on the job)
.setCronName(“daily_cron”) // set cron name (unique)
.build(); // build cron details
// MONTHLY CRON => which will be run on 0hrs 0mins 0sec on 1st 3rd and 5th days of every month
// generate cron details
ZCCronDetails monthlyCronDetails = ZCCronBuilder.zcMonthlyCronBuilder() // get monthly cron builder
.setCronStatus(true) // set cron as enabled
.setTime(0, 0, 0) // set the time of the day during which the cron should be executed
.setDays(1, 3, 5) // set the days of the month (day based config)
// .setWeeksOfMonth(1, 3) // set the weeks of the month (either week based or day based config is necessary)
// .setDayOfTheWeek(1, 2) // set the days of the week (either week based or day based config is necessary)
.setJobMeta(jobMeta) // set the job meta (modify based on the job)
.setCronName(“monthly_cron”) // set cron name (unique)
.build(); // build cron details
// YEARLY CRON => which will be run on 0hrs 0min 0sec on 1st 2nd 3rd days of the 8th month of a year
// generate cron details
ZCCronDetails yearlyCronDetails = ZCCronBuilder.zcYearlyCronBuilder() // get yearly cron builder
.setCronStatus(true) // set cron as enabled
.setTime(0, 0, 0) // set the time of the day during which the cron should be executed
.setDays(1, 2, 3) // set the days of the month
// .setWeeksOfMonth(1) // set the weeks of the month (either week based or day based config is necessary)
// .setDayOfTheWeek(3) // set the days of the week (either week based or day based config is necessary)
.setMonths(8) // set the months
.setJobMeta(jobMeta) // set the job meta (modify based on the job)
.setCronName(“yearly_cron”) // set cron name (unique)
.build(); // build cron details
// 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 functions’s Id (optional) (either target_id or target_name is mandatory)
jobpool_name: ’test’, // set the name of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
// jobpool_id: ‘1234567890’ // set the Id of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
job_config: {
number_of_retries: 2, // set the number of retries
retry_interval: 15 * 60 * 1000 + ’’ // 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)
};
// EVERY CRON => which will be run for every 2hrs 1min and 3sec
// create every cron details
const everyCron = {
cron_name: ’every_cron’, // set a name for the cron (unique)
cron_status: true, // set the cron status as enabled
cron_type: ‘Periodic’, // set the cron type as Periodic for every cron
cron_detail: {
hour: 2, // set the hour interval of the repetition
minute: 1, // set the minute interval of the repetition
second: 3, // set the second interval of the repetition
repetition_type: “every” // set the repetition type as every for every cron
},
job_meta: jobMeta // set the function job meta
};
// create every cron
const everyCronDetails = await jobScheduling.CRON.createCron(everyCron);
// DAILY CRON => which will be run on 0hrs 0mins and 0sec daily
// create daily cron details
const dailyCron = {
cron_name: ‘daily_cron’, // set a name for the cron (unique)
cron_status: true, // set the cron status as enabled
cron_type: ‘Calendar’, // set the cron type as Calendar for daily, monthly and yearly
cron_detail: {
hour: 0, // set the hour of the day in which the cron should be executed
minute: 0, // set the minute of the day in which the cron should be executed
second: 0, // set the second of the day in which the cron should be executed
repetition_type: ‘daily’ // set the repetition type as daily for daily cron
},
job_meta: jobMeta // set the function job meta
};
// MONTHLY CRON => which will be run on 0hrs 0mins 0sec on 1st 3rd and 5th days of every month
// create monthly cron details
const monthlyCron = {
cron_name: ‘monthly_cron’, // set a name for the cron (unique)
cron_status: true, // set the cron status as enabled
cron_type: ‘Calendar’, // set the cron type as Calendar for daily, monthly and yearly
cron_detail: {
hour: 0, // set the hour of the day in which the cron should be executed
minute: 0, // set the minute of the day in which the cron should be executed
second: 0, // set the second of the day in which the cron should be executed
days: [1, 3, 5], // set the days of the month in which the cron should be executed
// week_day: [1, 3], // set the days of the week in a month during which the cron should be executed
// weeks_of_month: [2], // set the weeks of the month during which the cron should be executed
repetition_type: ‘monthly’ // set the repetition type as monthly for monthly cron
},
job_meta: jobMeta // set function job meta
};
// YEARLY CRON => which will be run on 0hrs 0min 0sec on 1st 2nd 3rd days of the 8th month of a year
// create yearly cron details
const yearlyCron = {
cron_name: ‘yearly_cron’, // set a name for the cron (unique)
cron_status: true, // set the cron status as enabled
cron_type: ‘Calendar’, // set the cron type as Calendar for daily, monthly and yearly
cron_detail: {
hour: 0, // set the hour of the day in which the cron should be executed
minute: 0, // set the minute of the day in which the cron should be executed
second: 0, // set the second of the day in which the cron should be executed
days: [1, 2, 3], // set the days of the month in which the cron should be executed
// week_day: [1, 3], // set the days of the week in a month during which the cron should be executed
// weeks_of_month: [2], // set the weeks of the month during which the cron should be executed
months: [8], // set the months of the year in which the cron should be executed
repetition_type: ‘yearly’ // set the repetition type as yearly for yearly cron
},
job_meta: jobMeta // set function job meta
};
job_meta = {
‘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 functions’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 * 1000 # 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)
}
# EVERY CRON => which will be run for every 2hrs 1min and 3sec
create every cron
every_cron = job_scheduling.CRON.create({
‘cron_name’: ’every_cron’, # set a name for the cron (unique)
‘cron_status’: True, # set the cron status as enabled
‘cron_type’: ‘Periodic’, # set the cron type as Periodic for every cron
‘cron_detail’: {
‘hour’: 2, # set the hour interval of the repetition
‘minute’: 1, # set the minute interval of the repetition
‘second’: 3, # set the second interval of the repetition
‘repetition_type’: ’every’ # set the repetition type as every for every cron
},
‘job_meta’: job_meta # set the function job meta
})
# DAILY CRON => which will be run on 0hrs 0mins and 0sec daily
create daily cron
daily_cron = job_scheduling.CRON.create({
‘cron_name’: ‘daily_cron’, # set a name for the cron (unique)
‘cron_status’: True, # set the cron status as enabled
‘cron_type’: ‘Calendar’, # set the cron type as Calendar for daily, monthly and yearly
‘cron_detail’: {
‘hour’: 0, # set the hour of the day in which the cron should be executed
‘minute’: 0, # set the minute of the day in which the cron should be executed
‘second’: 0, # set the second of the day in which the cron should be executed
‘repetition_type’: ‘daily’ # set the repetition type as daily for daily cron
},
‘job_meta’: job_meta # set the function job meta
})
# MONTHLY CRON => which will be run on 0hrs 0mins 0sec on 1st 3rd and 5th days of every month
create monthly cron
monthly_cron = job_scheduling.CRON.create({
‘cron_name’: ‘monthly_cron’, # set a name for the cron (unique)
‘cron_status’: True, # set the cron status as enabled
‘cron_type’: ‘Calendar’, # set the cron type as Calendar for daily, monthly and yearly
‘cron_detail’: {
‘hour’: 0, # set the hour of the day in which the cron should be executed
‘minute’: 0, # set the minute of the day in which the cron should be executed
‘second’: 0, # set the second of the day in which the cron should be executed
‘days’: [1, 3, 5], # set the days of the month in which the cron should be executed
# ‘week_day’: [1, 3], # set the days of the week in a month during which the cron should be executed
# ‘weeks_of_month’: [2], # set the weeks of the month during which the cron should be executed
‘repetition_type’: ‘monthly’ # set the repetition type as monthly for monthly cron
},
‘job_meta’: job_meta # set function job meta
})
# YEARLY CRON => which will be run on 0hrs 0min 0sec on 1st 2nd 3rd days of the 8th month of a year
create yearly cron
yearly_cron = job_scheduling.CRON.create({
‘cron_name’: ‘yearly_cron’, # set a name for the cron (unique)
‘cron_status’: True, # set the cron status as enabled
‘cron_type’: ‘Calendar’, # set the cron type as Calendar for daily, monthly and yearly
‘cron_detail’: {
‘hour’: 0, # set the hour of the day in which the cron should be executed
‘minute’: 0, # set the minute of the day in which the cron should be executed
‘second’: 0, # set the second of the day in which the cron should be executed
‘days’: [1, 2, 3], # set the days of the month in which the cron should be executed
# ‘week_day’: [1, 3], # set the days of the week in a month during which the cron should be executed
# ‘weeks_of_month’: [2], # set the weeks of the month during which the cron should be executed
‘months’: [8], # set the months of the year in which the cron should be executed
‘repetition_type’: ‘yearly’ # set the repetition type as yearly for yearly cron
},
‘job_meta’: job_meta # set function job meta
})
View more
Define Dynamic Crons Using Cron Expressions
Dynamic Cron Using Cron Expressions
copy
// EXPRESSION CRON => which will be run for on 0hrs 0min on every 1st day of the weeks in the first month of the year
ZCJobScheduling jobScheduling = ZCJobScheduling.getInstance(); // get job scheduling instance
// generate function job meta
ZCJobMetaDetail jobMeta = ZCJobBuilder.functionJobBuilder() // get function job builder
.setJobConfig(2, 15 * 60 * 1000L) // set job config - job retries => 2 retries in 15 mins (optional)
.setJobpoolName(“functions_job_pool”) // set the name of the function job pool (optional) (either JobpoolId or JobpoolName is mandatory)
// .setJobpoolId(1234567890L) // set the Id of the function job pool (optional) (either JobpoolId or JobpoolName is mandatory)
.setTargetName(“target_function”) // set target function’s name (optional) (either TargetName or TargetId is mandatory)
// .setTargetId(1234567890L) // set the target function’s Id (optional) (either TargetName or TargetId is mandatory)
.setParams(new JSONObject() {
{
put(“arg1”, “job”);
put(“arg2”, “test”);
}
}) // set params to be passed to target function (optional)
.setJobName(“job_name”) // set job name
.build(); // build job meta
// generate cron details
ZCCronDetails expressionCronDetails = ZCCronBuilder.zcExpressionCronBuilder() // get expression corn builder
.setCronStatus(true) // set cron as enabled
.setCronExpression(“0 0 * 1 1”) // set the UNIX cron expression
.setCronName(“expression_cron”) // set cron name
.setJobMeta(jobMeta) // set job meta
.build(); // build cron details
// 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 functions’s Id (optional) (either target_id or target_name is mandatory)
jobpool_name: ’test’, // set the name of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
// jobpool_id: ‘1234567890’ // set the Id of the function job pool (optional) (either jobpool_name or jobpool_id is mandatory)
job_config: {
number_of_retries: 2, // set the number of retries
retry_interval: 15 * 60 * 1000 + ’’ // 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)
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
cron_detail: {}, // set the cron details
job_meta: jobMeta // set function job meta
};
job_meta = {
‘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 functions’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 * 1000 # 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
expression_cron = job_scheduling.CRON.create({
‘cron_name’: ’expression_cron’, # set a name for the cron (unique)
‘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
‘cron_detail’: {}, # set the cron details
‘job_meta’: job_meta # set function job meta
})
View more
Copy the code according to the requirement using the copy-icon and add it to your business logic and code according to your requirement.
The Dynamic Cron will be created during runtime, and the job configured in the code will be submitted to the job pool durring runtime at the configured schedule.
Note: Code snippets to create your required dynamic cron for each run time can also be found in each runtime's SDK documentation: