Overview

Defer allows you to schedule recurring executions. This is useful for example when you have a weekly newsletter to send to your users every Monday.

Even if your defer function is declared as a cron, you can still enqueue it anytime at your discretion, like a regular defer function.

You can schedule a recurring execution using the defer.cron() function rather than defer.

export default defer.cron(myFunc, "* * * * *");

With Defer CRON your schedule is defined in UTC.

Example

import { defer } from "@defer/client";

async function sendMondayNewletter() {
  // business logic here
}

export default defer.cron(sendMondayNewletter, "0 0 * * MON");

If you are not an expert of the CRON syntax, no worries! You can use the crontab.guru website to build your CRON expression!