Skip to main content
Version: v2.x

Creating a cron trigger

Introduction

Cron triggers are used to reliably trigger HTTP endpoints to run custom business logic periodically based on a cron schedule. For example, you can create a cron trigger to generate an end-of-day sales report every weekday at 10pm.

To add a cron trigger, follow these steps:

Step 1: Define the cron trigger

The following fields are required to define a cron trigger:

  • Name: A name for the cron trigger.
  • Webhook: The HTTP endpoint that should be triggered.
  • Cron schedule: A cron expression defining the schedule for the cron. Cron events are created based on the UTC timezone. You can use tools like crontab guru to help build a cron expression.
  • Payload: The JSON payload which will be sent to the webhook.

For example, we can create a cron trigger called eod_reports, to trigger the webhook https://mywebhook.com/eod with the cron schedule 0 22 * * 1-5, which means "At 22:00 on every day-of-week from Monday through Friday" (you can check this here).

Navigate to Events > Cron Triggers > Create in your Hasura console.

Adding a cron trigger

In the form opened, fill out the fields defined above:

You can use the link next to the Cron Schedule field to help build a cron expression using crontab guru, or use the Frequently used crons dropdown as a shortcut.

Defining a cron trigger

Step 2: Define advanced options (Optional)

If you like, you can also define the following values:

  • Headers: List of headers to be sent to the webhook.
  • Retry configuration: In case the call to the webhook fails.
  • Include in metadata: When set to true, the cron trigger will be included in the metadata and can be exported along with it.
  • Comment: Custom description of the cron trigger.

Expand the Advanced section.

Defining advanced options for a cron trigger

Schedule & logs

Once you've created your cron trigger, you can see Pending events, Processed events, and Invocation logs in their respective tabs.

Schedule and logs for cron triggers