@lands.io/mod-sdk / SchedulerJob
Class: SchedulerJob¶
Abstract base class for mod scheduler jobs. Extend this class to create scheduled background tasks.
Jobs are executed on a schedule defined by the cronExpression property. Minimum interval is 1 hour to prevent excessive resource usage.
Example
class LeaderboardUpdateJob extends SchedulerJob {
cronExpression = '0 0 * * * *'; // Every hour
async execute(context: SchedulerJobContext): Promise<void> {
context.log('Running leaderboard update');
// Update leaderboard data
const topPlayers = await context.storage?.getOrderedDesc('scores', 'elo', 10);
console.log('Top players:', topPlayers);
}
}
Table of contents¶
Constructors¶
Properties¶
Methods¶
Constructors¶
constructor¶
• new SchedulerJob(): SchedulerJob
Returns¶
Properties¶
cronExpression¶
• Abstract cronExpression: string
Cron expression defining when this job should run. Must have a minimum interval of 1 hour.
Format: second minute hour day month weekday Examples: - '0 0 * * * ' - Every hour - '0 0 0/2 * * ' - Every 2 hours - '0 0 12 * * *' - Every day at noon
Methods¶
execute¶
▸ execute(context): Promise\<void>
Execute the job logic. Called when the job is due to run.
Parameters¶
| Name | Type | Description |
|---|---|---|
context |
SchedulerJobContext |
Context with storage and mod info |
Returns¶
Promise\<void>
Throws
Error if the job fails
Source Code¶
View full implementation
/**
* Abstract base class for mod scheduler jobs.
* Extend this class to create scheduled background tasks.
*
* Jobs are executed on a schedule defined by the cronExpression property.
* Minimum interval is 1 hour to prevent excessive resource usage.
*
* @example
* ```typescript
* class LeaderboardUpdateJob extends SchedulerJob {
* cronExpression = '0 0 * * * *'; // Every hour
*
* async execute(context: SchedulerJobContext): Promise<void> {
* context.log('Running leaderboard update');
* // Update leaderboard data
* const topPlayers = await context.storage?.getOrderedDesc('scores', 'elo', 10);
* console.log('Top players:', topPlayers);
* }
* }
* ```
*/
export abstract class SchedulerJob {
/**
* Cron expression defining when this job should run.
* Must have a minimum interval of 1 hour.
*
* Format: second minute hour day month weekday
* Examples:
* - '0 0 * * * *' - Every hour
* - '0 0 0/2 * * *' - Every 2 hours
* - '0 0 12 * * *' - Every day at noon
*/
abstract cronExpression: string;
/**
* Execute the job logic.
* Called when the job is due to run.
*
* @param context Context with storage and mod info
* @throws Error if the job fails
*/
abstract execute(context: SchedulerJobContext): Promise<void>;
}