Provider Configuration
The scheduler is registered as a provider in your AdonisJS application. During installation, the provider is automatically configured in youradonisrc.ts file.
Provider Registration
The scheduler provider is registered for console environments:adonisrc.ts
The provider only loads in console environments (when running Ace commands), ensuring it doesn’t impact your HTTP server performance.
Environment-Specific Provider Loading
You can conditionally load the provider based on your environment:adonisrc.ts
Preload File Configuration
The scheduler is configured in thestart/scheduler.ts preload file, which is automatically created during installation.
Basic Preload Setup
start/scheduler.ts
Multiple Preload Files
For larger applications, you can organize schedules into multiple files:start/scheduler.ts
start/schedules/database_maintenance.ts
Advanced Scheduler Configuration
Global Lifecycle Hooks
Configure global hooks that run for all scheduled tasks:start/scheduler.ts
Timezone Configuration
Configure default timezone for all schedules:start/scheduler.ts
Tag-Based Organization
Organize schedules into logical groups using tags:start/scheduler.ts
Overlap Prevention Configuration
Prevent task overlapping globally or per schedule:start/scheduler.ts
The
expiresAt value is in milliseconds. It determines how long the lock is held. Default is 3600000ms (1 hour).Worker Configuration
Custom Worker Instance
For advanced use cases, you can manually instantiate and configure the worker:start/scheduler_worker.ts
Multiple Worker Instances
Run multiple scheduler workers with different tags:Container Bindings
The scheduler is bound to the IoC container and can be injected:Environment Variables
Configure scheduler behavior using environment variables:.env
start/scheduler.ts
Conditional Schedule Registration
Register schedules based on application state or configuration:start/scheduler.ts
Commands Configuration
The scheduler provides commands that are automatically registered:scheduler:run- Start the scheduler workerscheduler:list- List all registered schedules
Command Options
Thescheduler:run command supports several options:
scheduler:list command can filter by tag:
Production Considerations
Process Management
In production, use a process manager to keep the scheduler running:ecosystem.config.cjs
Graceful Shutdown
The scheduler handles termination signals gracefully, stopping all scheduled tasks before exiting.Next Steps
Troubleshooting
Common issues and debugging tips
Lifecycle Hooks
Learn about task lifecycle hooks