Interface for cron jobs that can be registered by modules
Cron jobs are executed when Cloudflare triggers match their schedule. Jobs are registered via the module's getCronJobs() method.
@Transient()export class DataCleanupJob implements CronJob { readonly schedule = '0 2 * * *' // Daily at 2 AM UTC constructor( @inject(LOGGER_TOKENS.LoggerService) private logger: LoggerService, ) {} async execute(controller: ScheduledController): Promise<void> { this.logger.info('Running data cleanup') await this.cleanupExpiredData() } async onError(error: Error): Promise<void> { this.logger.error('Data cleanup failed', { error: error.message }) }} Copy
@Transient()export class DataCleanupJob implements CronJob { readonly schedule = '0 2 * * *' // Daily at 2 AM UTC constructor( @inject(LOGGER_TOKENS.LoggerService) private logger: LoggerService, ) {} async execute(controller: ScheduledController): Promise<void> { this.logger.info('Running data cleanup') await this.cleanupExpiredData() } async onError(error: Error): Promise<void> { this.logger.error('Data cleanup failed', { error: error.message }) }}
Readonly
Cron expression that triggers this job
Must match a cron trigger defined in wrangler.jsonc
'0 2 * * *' // Daily at 2 AM UTC Copy
'0 2 * * *' // Daily at 2 AM UTC
'* /15 * * * *' // Every 15 minutes Copy
'* /15 * * * *' // Every 15 minutes
Execute the cron job
Cloudflare ScheduledController with scheduledTime and cron
ApplicationError for expected errors
Optional
Optional error handler for job execution failures
If not provided, errors are logged via GlobalErrorHandler
Error that occurred during execution
Cloudflare ScheduledController
Interface for cron jobs that can be registered by modules
Cron jobs are executed when Cloudflare triggers match their schedule. Jobs are registered via the module's getCronJobs() method.
Example