Files
matrix-bot/src/core/plugin/scheduler.ts
T

12 lines
419 B
TypeScript

import { CronJob } from 'cron';
export interface Scheduler {
register(cron: string, timeZone: string, run: () => Promise<void>): () => void;
}
export class PluginScheduler implements Scheduler {
register(cron: string, timeZone: string, run: () => Promise<void>): () => void {
const job = new CronJob(cron, () => { void run().catch(() => undefined); }, null, true, timeZone);
return () => job.stop();
}
}