โจ Trigger.dev Basic CRON Workflow
This repo contains a simple CRON job workflow that runs every weekday at 9:00 AM UTC.
It is a great starting point for creating your own scheduled workflows.
To easily create CRON schedules, we recommend using crontab.guru.
import { Trigger, scheduleEvent } from "@trigger.dev/sdk";
new Trigger({
// Give your Trigger a stable ID
id: "cron-basic",
name: "Trigger event at 9am every weekday",
//Trigger this event at 09:00 on every day-of-week from Monday through Friday. (https://crontab.guru/#0_9_*_*_1-5)
on: scheduleEvent({ cron: "0 9 * * 1-5" }),
run: async (event, ctx) => {
// This can be anything - e.g. update your database, send an email or post a daily Slack update etc
// Create a log at the correct time
await ctx.logger.info("Received the cron scheduled event", {
event,
});
},
}).listen();๐ง Install
You can easily create a new project interactively based on this template by running:
npx create-trigger@latest cron-basic
# or
yarn create trigger cron-basic
# or
pnpm create trigger@latest cron-basicFollow the instructions in the CLI to get up and running locally in <30s.
๐งช Test it
After successfully running this template locally, head over to your Trigger.dev Dashboard and you should see your newly created workflow.
โ๏ธ Customize
You can easily adapt this workflow for example, we have a workflow that runs once a year on the 1st of January and posts a Slack message wishing our team a Happy New Year.
import { Trigger, scheduleEvent } from "@trigger.dev/sdk";
import * as slack from "@trigger.dev/slack";
new Trigger({
// Give your Trigger a stable ID
id: "cron-happy-new-year",
name: "Happy New Year!",
//Trigger this event at 12am every 1st of January, every year.
on: scheduleEvent({ cron: "0 12 1 1 *" }),
run: async (event, ctx) => {
// This can be anything - e.g. update your database, send an email or post a daily Slack update etc
// log the event at the correct time
await slack.postMessage("๐จ", {
channelName: "happy-new-year",
text: `๐ Happy New Year team! ๐ `,
});
},
}).listen();Be sure to check out more over on our docs