Skip to main content
This guide covers advanced configuration patterns for AdonisJS Scheduler, including provider setup, environment-based configuration, and custom worker configuration.

Provider Configuration

The scheduler is registered as a provider in your AdonisJS application. During installation, the provider is automatically configured in your adonisrc.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 the start/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:
When running multiple workers, ensure each worker handles a unique set of tags to avoid duplicate task execution.

Container Bindings

The scheduler is bound to the IoC container and can be injected:
Or resolve it from the container:

Environment Variables

Configure scheduler behavior using environment variables:
.env
Use them in your configuration:
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 worker
  • scheduler:list - List all registered schedules

Command Options

The scheduler:run command supports several options:
The 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