Cron Functions

Introduction

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. However, you can use the functions:shell command to test it in the CLI. A Cron function does not return any response other than determining if the function execution was a success or failure.


Cron Function Modules

Java

A Catalyst Cron Function supports two modules in Java: CronRequest and Context.

The CronRequest module contains the following built-in methods:

  1. CronRequest.getCronParam(): This method is used to get the value of the particular parameter passed to the function.
  2. CronRequest.getAllCronParams(): This method is used to get all the parameters passed to the function.
  3. CronRequest.getRemainingExecutionCount(): This method is used to get the details about the remaining execution instances of a cron job.
  4. CronRequest.getCronDetails(): This method is used to get the cron’s details such as the Cron ID and the cron name.
  5. CronRequest.getProjectDetails(): Used to get the project details, such as the project ID and project name.

The Context module contains the following built-in methods:

  1. Context.getMaxExecutionTimeMs(): This method can be used to get the maximum execution time of a cron function, which is a constant value of 15 minutes.
  2. Context.getRemainingExecutionTimeMs(): This can be used to fetch the remaining execution time of a cron function.

When you execute a Java function, it returns the status of the execution as either SUCCESS or FAILURE at the end of its execution. The returned status is of type com.catalyst.cron.CRON_STATUS.


Node.js

The Catalyst Cron Function supports two modules in Node.js: cronDetails and context.

The cronDetails module contains the following built-in methods:

  1. cronDetails.getCronParam(): This method is used to get the value of the particular parameter passed to the function.
  2. cronDetails.getAllCronParam(): This method is used to get all the parameters passed to the function.
  3. cronDetails.getRemainingExecutionCount(): To get the details about the remaining execution instances of the cron job.
  4. cronDetails.getCronDetails(): To get the cron’s details such as the Cron ID and the cron name.
  5. cronDetails.getProjectDetails(): To get the project details, such as the project ID and project name.

The context module contains the following built-in methods:

  1. context.getMaxExecutionTimeMs(): This method can be used to get the maximum execution time of a function, which is a constant value of 15 minutes.
  2. context.getRemainingExecutionTimeMs(): This can be used to fetch the remaining execution time of a function.
  3. context.closeWithSuccess(): This method is used to indicate that the function executed successfully. You must use this at the end of the function.
  4. context.closeWithFailure(): This method is used to indicate that the function’s execution was a failure. You must use this at the end of the function.

Python

A Catalyst Cron Function supports two modules in Python as well: cron_details and context.

The cron_details module contains the following built-in methods:

  1. cron_details.get_cron_param() - This method is used to get the value of the particular parameter passed to the function.
  2. cron_details.get_all_cron_params() - This method is used to get all the parameters passed to the function.
  3. cron_details.get_remaining_execution_count() - To get the details about the remaining execution instances of the cron job.
  4. cron_details.get_cron_details() - To get the cron’s details such as the Cron ID and the cron name.
  5. cron_details.get_project_details() - To get the project details, such as the project ID and project name.

The context module contains the following built-in methods:

  1. context.get_max_execution_time_ms() - This method can be used to get the maximum execution time of a function. And the maximum execution time of a function is configured to be 15 mins.
  2. context.get_remaining_execution_time_ms() - This can be used to fetch the remaining execution time of a function.
  3. context.close_with_success() - This can be used to indicate that the function executed successfully. You must use this at the end of the function.
  4. context.close_with_failure() - To indicate that the function’s execution was a failure. You must use this at the end of the function.

Last Updated 2023-10-12 19:23:27 +0530 +0530