Skip to main content

Class: Crons

For AI agents: see llms.txt for the complete documentation index. Markdown versions are available by adding .md to a page URL or requesting Accept: text/markdown.

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:284

Properties​

crons​

• crons: Record<string, CronJob>

Defined in​

server/cron.ts:282


isCrons​

• isCrons: true

Defined in​

server/cron.ts:283

Methods​

interval​

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

Schedule a mutation or action to run at some interval.

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

Type parameters​

NameType
FuncRefextends SchedulableFunctionReferenceCompat

Parameters​

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

Returns​

void

Defined in​

server/cron.ts:321


hourly​

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

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

crons.hourly(
"Reset high scores",
{
minuteUTC: 30,
},
api.scores.reset
)

Type parameters​

NameType
FuncRefextends SchedulableFunctionReferenceCompat

Parameters​

NameTypeDescription
cronIdentifierstringA unique name for this scheduled job.
functionReferenceFuncRefA FunctionReference or FunctionReference_future for the function to schedule.
...argsOptionalRestArgs<FuncRef>The arguments to the function.

Returns​

void

Defined in​

server/cron.ts:370

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

Type parameters​

NameType
FuncRefextends SchedulableFunctionReferenceCompat

Parameters​

NameType
cronIdentifierstring
scheduleHourly
functionReferenceFuncRef
...argsOptionalRestArgs<FuncRef>

Returns​

void

Defined in​

server/cron.ts:375


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 SchedulableFunctionReferenceCompat

Parameters​

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

Returns​

void

Defined in​

server/cron.ts:431


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",
{
dayOfWeek: "Tuesday",
hourUTC: 17, // (9:30am Pacific/10:30am Daylight Savings Pacific)
minuteUTC: 30,
},
api.emails.send
)

Type parameters​

NameType
FuncRefextends SchedulableFunctionReferenceCompat

Parameters​

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

Returns​

void

Defined in​

server/cron.ts:469


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 SchedulableFunctionReferenceCompat

Parameters​

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

Returns​

void

Defined in​

server/cron.ts:512


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 SchedulableFunctionReferenceCompat

Parameters​

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

Returns​

void

Defined in​

server/cron.ts:551