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
Properties
crons
• crons: Record
<string
, CronJob
>
Defined in
isCrons
• isCrons: true
Defined in
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
Name | Type |
---|---|
FuncRef | extends SchedulableFunctionReference |
Parameters
Name | Type | Description |
---|---|---|
cronIdentifier | string | - |
schedule | Interval | The time between runs for this scheduled job. |
functionReference | FuncRef | A FunctionReference for the function to schedule. |
...args | OptionalRestArgs <FuncRef > | The arguments to the function. |
Returns
void
Defined in
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
Name | Type |
---|---|
FuncRef | extends SchedulableFunctionReference |
Parameters
Name | Type | Description |
---|---|---|
cronIdentifier | string | A unique name for this scheduled job. |
schedule | Hourly | What time (UTC) each day to run this function. |
functionReference | FuncRef | A FunctionReference for the function to schedule. |
...args | OptionalRestArgs <FuncRef > | The arguments to the function. |
Returns
void
Defined in
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
Name | Type |
---|---|
FuncRef | extends SchedulableFunctionReference |
Parameters
Name | Type | Description |
---|---|---|
cronIdentifier | string | A unique name for this scheduled job. |
schedule | Daily | What time (UTC) each day to run this function. |
functionReference | FuncRef | A FunctionReference for the function to schedule. |
...args | OptionalRestArgs <FuncRef > | The arguments to the function. |
Returns
void
Defined in
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
Name | Type |
---|---|
FuncRef | extends SchedulableFunctionReference |
Parameters
Name | Type | Description |
---|---|---|
cronIdentifier | string | A unique name for this scheduled job. |
schedule | Weekly | What day and time (UTC) each week to run this function. |
functionReference | FuncRef | A FunctionReference for the function to schedule. |
...args | OptionalRestArgs <FuncRef > | - |
Returns
void
Defined in
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
Name | Type |
---|---|
FuncRef | extends SchedulableFunctionReference |
Parameters
Name | Type | Description |
---|---|---|
cronIdentifier | string | A unique name for this scheduled job. |
schedule | Monthly | What day and time (UTC) each month to run this function. |
functionReference | FuncRef | A FunctionReference for the function to schedule. |
...args | OptionalRestArgs <FuncRef > | The arguments to the function. |
Returns
void
Defined in
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
Name | Type |
---|---|
FuncRef | extends SchedulableFunctionReference |
Parameters
Name | Type | Description |
---|---|---|
cronIdentifier | string | A unique name for this scheduled job. |
cron | string | Cron string like "15 7 * * *" (Every day at 7:15 UTC) |
functionReference | FuncRef | A FunctionReference for the function to schedule. |
...args | OptionalRestArgs <FuncRef > | The arguments to the function. |
Returns
void