A Cron function is a periodic function that is associated with a Cron. You can create a Cron function to execute a job that needs to be invoked one time or periodically.
When you configure a cron in Catalyst, you can associate it with executing a function or invoking a third-party URL.
When the cron is associated with a function, the cron job invokes the function automatically based on its schedule. If it is a one-time job, the cron invokes the function on the specified date and time. If it is periodic, the cron invokes the function at the configured intervals, such as every month on a specific date and time, or everyday on a specific time.
You cannot invoke a Cron function manually, or test it in the console or the CLI. A Cron function does not return any response other than determining if the function execution was a success or failure.
Java, Node.js and Python Modules
A Catalyst Cron function supports two modules in Node.js and Python: context and cronDetails.
The context module in Node.js and Python includes the following built-in methods:
- context.closeWithSuccess():: To indicate that the function executed successfully. You must use this at the end of the function.
- context.closeWithFailure():: To indicate that the function’s execution was a failure. You must use this at the end of the function.
The cronDetails module in Node.js and Python includes the following built-in methods:
- cronDetails.getProjectDetails():: To get the project details, such as the project ID and project name
- cronDetails.getCronDetails():: To get the cron’s details such as the Cron ID and the cron name
- cronDetails.getRemainingExecutionCount():: To get the details about the remaining execution instances of the cron job
- cronDetails.getCronParam():: To get the parameters passed to the function
A Cron function in Java supports the same modules and built-in methods as Node.js and Python except cronDetails.getCronParam(). Instead of it, the following methods are used in Java:
- cronDetails.getArgument():: To get a single parameter passed to the function by its key value
- cronDetails.getAllArguments():: To get all parameters passed to the function
You can check the default code structure created for a Cron function, based on the stack, from the Catalyst console or your function directory in your local system.
Last Updated 2023-05-30 16:31:35 +0530 +0530
Send your feedback to us