Cron

Cron

 

Introduction

Catalyst Cron is a job scheduler that can be used to automate the execution of jobs periodically at specified schedules or intervals. Catalyst initiates the cron daemon to run in the background at all times. The cron daemon is a program that handles invoking a cron job when its determined schedule approaches.

You can use Catalyst Cron to run administrative and maintenance tasks periodically or to automate the execution of specific schedule-based processes in the application. Some scenarios where cron can be used include: periodically synchronizing your Catalyst data with a third-party application, updating a cache item's value at regular intervals, or sending monthly, automated, system-generated emails to your application users.

Catalyst Cron can automatically invoke either third-party URLs or Cron functions at specified schedules. Cron functions are custom coding structures that contain the logic of the job to be executed by a cron. You can code them to perform recurring tasks such as backing up data or any one-time tasks that need to be executed at a custom schedule. You can schedule the cron job to be executed once or recursively by defining the specific date and time of the execution or the interval period for recursion.

Catalyst enables you to easily create and configure cron jobs from the remote console. You can also manage cron jobs or view cron resource statistics using these components:

  1. Application alerts: Catalyst enables developers to configure automatic alerts to be sent to specific email addresses when a Catalyst cron encounters failure, code exception, or timeout.
  2. Metrics: You can view usage statistics of the cron jobs in your project, such as the- number of active or inactive jobs and the execution count of each cron job.

To practice working with Catalyst cron, refer to this tutorial.

Key Concepts

Before you learn about configuring a cron, it's important to understand certain key concepts and terminology about Catalyst Cron.

Task Engine

The task engine handles the backend logic of cron and handles the execution of cron jobs as per their defined schedule time.

Schedule Point

The schedule point determines the entity to trigger when a cron job is executed. A cron can trigger either of the following:

Function: You can code a cron function to execute any one-time or recurring routine job that you require. You can pass parameter values to this target function dynamically when the function is called, if needed. You can also insert a placeholder in a parameter. A placeholder is a representational variable for the dynamic value that is passed. When the value is generated at the time of execution, it replaces the placeholder variable.

Third-party URL: When a cron's execution invokes a third-party URL, it sends a HTTP request to the target URL that you specify. This allows for data transmission to occur between Catalyst and the specified target URL, where Catalyst can read data from the destination server or input your application's data to the corresponding components in the server. The following components are involved in sending a request to the third-party URL:

  • HTTP request methods The following HTTP request methods are supported while invoking a third-party URL by a cron:
    • POST: Creates a new resource in the target URL
    • GET: Retrieves data from the target URL
    • PUT: Replaces an existing resource in the target URL
    • DELETE: Deletes an existing resource in the target URL
  • Headers

    When the HTTP request is sent to the target URL, the requesting entity sends default headers in the request to provide information about the request. Some examples of default headers include the origin of the request, the connection type, and the Content-Type.

    In addition to the default headers, you can also define custom headers in the HTTP request. For example, you can include a header that specifies the authorization type used, a list of acceptable encoding, or the origin date of the request.

    Note: If you use the HTTP POST or PUT methods in your request, you should set the content-type of the data that is sent in the header. The content-types that are supported are TEXT (text/plain), JSON (application/JSON), JavaScript (application/javascript), XML (application/xml), XML (text/xml), and HTML (text/html).
  • URL Parameters

    You can pass custom URL parameters in the User-Defined format with the HTTP request, whose values are set dynamically when the third-party URL is invoked. You can customize the parameter value and include any terms that you require to be passed in the parameter.

  • Request Body

    You can include an optional HTTP request body while invoking the URL, which can be used to carry form data and other optional data. You can pass the form data in the optional message body in various formats.

Schedule Type

The schedule type determines the frequency of a cron job's execution. A cron can be executed in one of two ways:

  • One Time: The cron job is triggered only once on the configured date and time.
  • Recursive: The cron job is triggered multiple times recursively based on the frequency, date, and time you configure, until you disable or delete it. The minimum recurring frequency a cron can be triggered at is one hour.

Execution ID

Each cron job is assigned a unique Execution ID when the cron is invoked. You can use this ID to refer to the cron job in your application code or while viewing its execution logs.

Architecture

Catalyst cron is a wrapper for the Zoho task engine. The task engine consists of a cron job scheduler and a backend server.

The cron jobs that are created in the Catalyst console are handled by the task engine. The job scheduler handles the sorting of jobs and passes each job to the task engine server at its invocation time that you configure.

The cron jobs are then executed by the task engine server at the scheduled time, based on its configurations.The server either invokes the associated cron function or the configured third-party URL.

Cron Workflow

The workflow of Cron operations in Catalyst is as follows:

  • Create a cron in the catalyst console.
  • The console passes all the cron jobs as they are created to the task engine, along with its configurations including its schedule type and point.
  • At a cron's scheduled execution time, the job scheduler passes the job details to the task engine server, which then handles its execution. The server will invoke either the associated cron function or the third-party URL.
  • The execution status and job details of the executed cron job fetched from the Task Engine are then passed on and rendered in the console in the Execution History section.

    catalyst_cron_architecture

Benefits

  • Effortless to Implement

    You can define the logic of the cron function with relative ease by choosing the Catalyst Cron function template from the CLI, removing the need for additional resources and time to code from scratch. You don't have to manually set up an elaborate backend, as Catalyst handles the complex backend logic, providing you with a seamless developer experience.

  • Seamlessly Scalable

    Catalyst servers can seamlessly handle heavy workload and they can automatically scale up or down based on the requirement. This enables developers to solely focus on configuring the cron job and coding the logic, without needing to perform any additional coding to handle the backend setup. Catalyst's cron jobs execute seamlessly regardless of the load.

  • Easy and Effective Testing

    You can test cron functions without having to set-up elaborate test plans. Using the function shell in the CLI. Here you can execute the cron function, and if there are no errors a Success message will be displayed. In the event of an error, the error message and details will be displayed in the CLI and a detailed report of the error can be viewed in the Logs section of the console.

  • Execution History

    Catalyst logs every cron job that is executed and makes them immediately available in the Execution History section. These logs enable you to assess the performance of your cron jobs and cron functions, debug errors and perform quick fixes, and make informed decisions based on analytics and reports. The execution history is available for 15 days in the development environment and 30 days in the production environment.

  • Immediate and Precise Alerts

    Catalyst provides you with the advantage of configuring custom, automated alerts to receive when a cron encounters an exception, failure, or a time out through Application Alerts. Catalyst will send these alerts immediately via email upon the cases you specify. This enables you to easily keep a track of the cron jobs in all your projects and implement immediate fixes during failures.

Use Cases

  • Applications that update data periodically

    Certain applications fetch updated data periodically from an external server and display it to their users. For example, a weather application or an application that provides live stock and securities market updates. You can easily build such applications in Catalyst and handle the periodical third-party API invocations automatically in your required time interval or schedule using Catalyst cron. You can explore a similar use case in detail by trying out the NewsApp tutorial.

  • Scheduled backups

    Backups are crucial in creating required redundancies of data that can be accessed easily, in the event of the original data being accidentally lost or compromised. Catalyst saves you the time and effort in performing backups manually. You can simply configure a cron to the job, and take automatic backups of your data at the time or interval you require.

  • Efficient Handling of Recursive Administrative Operations

    Human resources operations, such as generating and release of payslips, submission of daily operational reports, and maintenance of employee attendance records, are crucial for the functioning of any organization. Configuring the necessary cron function will ensure that these operations are carried out automatically and per schedule without dedicating additional resources.

  • Handling Operation Redundancies

    If you consider the process workflow of an organization, especially a tech-centric organization, the infrastructure is generally set up in a way to optimize interoperability. But implementing smooth interoperability creates a large number of redundant tasks, such as rotating log files, syncing files, and cleaning up temporary files. Although redundant, these processes are vital, and implementing dedicated cron jobs to handle these operations would ensure that the tasks are carried out periodically and with no additional manual intervention once the job is set to execute.

  • Alert-based applications

    Recursive cron jobs can be used in designing applications that send automatic alerts to users frequently. For example, you can build an application that alerts users when they are close to crossing the safety threshold of their expense account.

  • User-configured applications

    Catalyst cron can process dynamic inputs, You can fetch inputs for a cron job's schedule from your application's users and dynamically execute required logic. This will be helpful in applications like health apps that alert users whenever they need to take their medicines. The users can determine the frequency and schedule of the alerts based on their requirements, and you can write your application logic to process these inputs.

Implementation

You can create, configure, modify, and delete cron jobs from the console. The implementation section covers steps to work with cron from the console.

Note: Catalyst allows up to 500 cron executions per project per day in the development environment. You can request Catalyst for an increase in this limit by contacting our support at support@zohocatalyst.com. We will address each request on a case-by-case basis. There are no upper limits for cron execution in the production environment.

Create a Cron

To create a Catalyst cron in your project from the console:

  1. Navigate to Cron under the Develop section.

  2. Click Create Cron.

    catalyst_cron_empty
  3. Enter the cron's name and an optional description in the Create Cron section.

    catalyst_cron_name_des

    Third-party URL

    If you choose to invoke a third-party URL for the cron:

    catalyst_cron_schedule_point_thirdparty_config
    • Enter the Target URL.
    • Select the HTTP request method to invoke the URL with, from the drop-down list.
    • Enter the Header Name and Header Value. To add more headers, click (+) and add the next header. To delete a header, click (-).
    • Add URL parameters to be passed, if needed, by entering their names and values. To add more parameters, click (+) and add the next parameter. To delete a parameter, click (-).
    • To include an optional request body, enter the form data that you want to be passed in the HTTP message body.

    Function

    If you choose to call a function for the cron:

    catalyst_cron_schedule_point_function_config
    • Select the Target Function from the drop-down list. The list will only display the cron functions configured in your project, and not other types of functions.
    • Add function parameters to be passed, if needed, by entering their names and values.
    • To add more parameters, click (+) and add the next parameter. To delete a parameter, click (-).
  4. Select the Schedule Type of the cron as One Time or Recursive.

    One-time execution

    • Select the Repeat Type for a recursive cron from the drop-down list as Every, Daily, Monthly, or Yearly.

      catalyst_cron_all_recursive_types
    • If you select the Repeat Type as Every, configure the hours, minutes, and seconds of the time from the drop-down lists to specify the frequency. The cron will be executed once every specified time interval. For example, in the screenshot below, the cron will be executed once every hour.

      catalyst_cron_schedule_type_recursive_every
    • If you select the Repeat Type as Daily, configure the hours, minutes, and seconds of the time period for the cron to execute. The cron will be executed everyday at the specified time.

      catalyst_cron_schedule_type_recursive_daily
    • If you select the Repeat Type as Monthly, you can choose to schedule the cron's execution by the date of the month or by the week of the month, to be executed on a specified day.

      • Select Day if you want to schedule the cron's execution by the date of the month. Click on all the dates of the month the cron must be executed on, from the calendar.

        catalyst_cron_recursive_monthly_day
      • Select Week if you want to schedule the cron's execution by the week of the month. Click the Select Week tab and choose the week from the drop-down list. Click the Select Day tab and select the day the cron should be executed on from the drop-down list.

        catalyst_cron_recursive_monthly_weekly
      • After you select the days, configure the time for the cron to be executed on from the Hours, Minutes, and Seconds drop-down lists.

        catalyst_cron_recursive_monthly_3
    • If you select the Repeat Type as Yearly, select all the months the cron must be executed on, from the Months drop-down list.

      catalyst_cron_recursive_yearly

      After you select the months, you can schedule the cron's execution by the date of the month or by the week of the month, as mentioned in the previous step. You can then configure the time in the same way as the previous step.

  5. catalyst_cron_schedule_type_onetime_config
    • Select the schedule date the cron must be executed on, from the calendar.
    • Configure the hour, minute, and second from their drop-down lists.
    • Choose the time zone of the execution. The cron will be executed on the configured time in that time zone.

    Recursive

  6. After you configure all the details, click Save.

    Catalyst will now display the cron job in the Cron page along with its details. A unique Cron ID is automatically created for a cron when it is created, and displayed in the details. You can refer to a cron by its ID in your application code.

    catalyst_cron_viewcron

    You can click on a cron to view further details about it.

    catalyst_cron_dets

Configuring Alerts in Cron

You can configure application alerts for the events where your cron may encounter a failure, code exception, or time out. You can configure email alerts from the cron console without having to navigate to the Application Alerts component.

  1. Click + Configure in the cron's details section to create an alert.

    catalyst_cron_create_alert
  2. Click Confirm once you configure the application alert. You can refer to the Application Alerts help page for details.

    catalyst_cron_cofinguration_alert
  3. You can also delete the application alert by clicking the ellipsis icon beside the alert status and clicking Remove.

    catalyst_cron_delete_alert

Enable or Disable a Cron

You can temporarily enable or disable a cron job using the toggle switch under the Status column. If you disable a cron, Catalyst will not trigger its execution until you manually enable it again.

catalyst_cron_status
Note: If a cron associated with a third-party URL fails in its executions 50 times in a row, Catalyst will automatically disable it. You can configure Application Alerts to automatically notify you whenever a cron's execution fails. You can then check the cron's execution history from the console and perform the required bug fixes. Cron jobs associated with cron functions will not be disabled automatically irrespective of repeated failures.

Cron Execution History

You can view the history and details of a cron's execution from its Execution History. Click the icon under the History column for a cron to open its execution history.

catalyst_cron_execution_hisotry

Catalyst displays the execution log of all cron job executions in your project. This contains detailed information about the cron job, such as the Execution ID, the start and end time, the execution time, the executive status, and links to Catalyst Logs.

catalyst_cron_execution_history

You can click View Logs to check detailed logs about the corresponding cron function's execution.

Note: Catalyst retains the execution history of a cron job for 15 days in the development environment, and 30 days in the production environment.

Edit a Cron

To edit a configured cron:

  1. Open the cron that needs to be edited from the Cron page.
  2. Click Edit in its details page.

    catalyst_cron_edit_cron
  3. Make the necessary changes, then click Save.

    catalyst_cron_edit_save_cron

Delete a Cron

To delete a cron permanently:

  1. Click the ellipsis icon for the cron that needs to be deleted, then click Delete.

    catalyst_cron_delete_select
  2. Click Yes, Proceed to confirm the delete.

    catalyst_cron_delete_popup

The cron is now deleted.

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohocatalyst.com