CRON

Trigger your Repeat on a schedule!

The CRON event allows you to trigger a Repeat on a schedule.

Event

declare interface Cron {
	id: string; // not currently used
	schedule: string;
}

Properties

  • id
    • Currently unused.

  • schedule
    • The CRON schedule that invoked your Repeat, such as 1 * * * *.

Signature

export default {
	async cron(cron: Repeat.Cron, env: Repeat.Env) {
		// ...
	},
};

Parameters

  • cron
    • The CRON schedule that invoked the Repeat.

  • env
    • The env object represents the Repeat’s environment, such as variables, storage and metrics as well as the various webhook integrations for different platforms.

Returns

  • void
    • Your webhook handler does not need to return a response, but you return one optionally if necessary.

Examples

Fetch an API on a schedule

  1. In the Events tab on the sidebar, click on + add cron and add a Every minute CRON.
Notion image
  1. Click on New repeat in the top menu bar, and then CRON job
export default {
	async cron(cron: Repeat.Cron, env: Repeat.Env) {
		const response = await fetch('https://httpbin.org/anything');

		if (response.ok) {
			env.metrics.write('response successful', 1);
		}
	},
};

This will send a request to https://httpbin.org/anything every minute and, if the request was successful, write to your Repeat’s metrics for you to view at a later date.

Last updated on November 12, 2022