Skip to main content

Class: Crons

server.Crons

A class for scheduling cron jobs.

To learn more see the documentation at https://docs.convex.dev/scheduling/cron-jobs

Constructors

constructor

new Crons()

Defined in

server/cron.ts:246

Properties

crons

crons: Record<string, CronJob>

Defined in

server/cron.ts:244


isCrons

isCrons: true

Defined in

server/cron.ts:245

Methods

interval

interval<FuncRef>(cronIdentifier, schedule, functionReference, ...args): void

Schedule a mutation or action to run on an hourly basis.

crons.interval("Clear presence data", {seconds: 30}, api.presence.clear);

Type parameters

NameType
FuncRefextends SchedulableFunctionReference

Parameters

NameTypeDescription
cronIdentifierstring-
scheduleIntervalThe time between runs for this scheduled job.
functionReferenceFuncRefA FunctionReference for the function to schedule.
...argsOptionalRestArgs<FuncRef>The arguments to the function.

Returns

void

Defined in

server/cron.ts:283


hourly

hourly<FuncRef>(cronIdentifier, schedule, functionReference, ...args): void

Schedule a mutation or action to run on a daily basis.

crons.daily(
"Reset high scores",
{
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
},
api.scores.reset
)

Type parameters

NameType
FuncRefextends SchedulableFunctionReference

Parameters

NameTypeDescription
cronIdentifierstringA unique name for this scheduled job.
scheduleHourlyWhat time (UTC) each day to run this function.
functionReferenceFuncRefA FunctionReference for the function to schedule.
...argsOptionalRestArgs<FuncRef>The arguments to the function.

Returns

void

Defined in

server/cron.ts:332


daily

daily<FuncRef>(cronIdentifier, schedule, functionReference, ...args): void

Schedule a mutation or action to run on a daily basis.

crons.daily(
"Reset high scores",
{
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
},
api.scores.reset
)

Type parameters

NameType
FuncRefextends SchedulableFunctionReference

Parameters

NameTypeDescription
cronIdentifierstringA unique name for this scheduled job.
scheduleDailyWhat time (UTC) each day to run this function.
functionReferenceFuncRefA FunctionReference for the function to schedule.
...argsOptionalRestArgs<FuncRef>The arguments to the function.

Returns

void

Defined in

server/cron.ts:367


weekly

weekly<FuncRef>(cronIdentifier, schedule, functionReference, ...args): void

Schedule a mutation or action to run on a weekly basis.

crons.weekly(
"Weekly re-engagement email",
{
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
},
api.emails.send
)

Type parameters

NameType
FuncRefextends SchedulableFunctionReference

Parameters

NameTypeDescription
cronIdentifierstringA unique name for this scheduled job.
scheduleWeeklyWhat day and time (UTC) each week to run this function.
functionReferenceFuncRefA FunctionReference for the function to schedule.
...argsOptionalRestArgs<FuncRef>-

Returns

void

Defined in

server/cron.ts:402


monthly

monthly<FuncRef>(cronIdentifier, schedule, functionReference, ...args): void

Schedule a mutation or action to run on a monthly basis.

Note that some months have fewer days than others, so e.g. a function scheduled to run on the 30th will not run in February.

crons.monthly(
"Bill customers at ",
{
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
day: 1,
},
api.billing.billCustomers
)

Type parameters

NameType
FuncRefextends SchedulableFunctionReference

Parameters

NameTypeDescription
cronIdentifierstringA unique name for this scheduled job.
scheduleMonthlyWhat day and time (UTC) each month to run this function.
functionReferenceFuncRefA FunctionReference for the function to schedule.
...argsOptionalRestArgs<FuncRef>The arguments to the function.

Returns

void

Defined in

server/cron.ts:443


cron

cron<FuncRef>(cronIdentifier, cron, functionReference, ...args): void

Schedule a mutation or action to run on a recurring basis.

Like the unix command cron, Sunday is 0, Monday is 1, etc.

 ┌─ minute (0 - 59)
│ ┌─ hour (0 - 23)
│ │ ┌─ day of the month (1 - 31)
│ │ │ ┌─ month (1 - 12)
│ │ │ │ ┌─ day of the week (0 - 6) (Sunday to Saturday)
"* * * * *"

Type parameters

NameType
FuncRefextends SchedulableFunctionReference

Parameters

NameTypeDescription
cronIdentifierstringA unique name for this scheduled job.
cronstringCron string like "15 7 * * *" (Every day at 7:15 UTC)
functionReferenceFuncRefA FunctionReference for the function to schedule.
...argsOptionalRestArgs<FuncRef>The arguments to the function.

Returns

void

Defined in

server/cron.ts:480