Choose a different Template

A basic CRON job workflow template

This template contains a simple CRON job workflow that runs every weekday at 9:00 AM UTC.

Help and guides

Get started

Run this command in your terminal to create a new project using this template.

npx create-trigger cron-basic

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-basic

Follow 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