Skip to main content
Installing AdonisJS Scheduler is straightforward using the official AdonisJS package manager integration.

Requirements

  • AdonisJS v6.2.0 or higher
  • Node.js v18 or higher

Installation steps

1

Install the package

Run the following command in your AdonisJS project:
node ace add adonisjs-scheduler
This command will:
  • Install the adonisjs-scheduler package from npm
  • Register the scheduler provider in your adonisrc.ts file
  • Register scheduler commands for running the scheduler
  • Create a start/scheduler.ts file with example schedules
  • Add the scheduler file to the preload configuration
2

Verify the configuration

After installation, your adonisrc.ts should include the following additions:
import { defineConfig } from '@adonisjs/core/app'

export default defineConfig({
  // ... other config
  
  providers: [
    // ... other providers
    () => import('adonisjs-scheduler/scheduler_provider'),
  ],
  
  commands: [
    // ... other commands
    () => import('adonisjs-scheduler/commands'),
  ],
  
  preloads: [
    // ... other preload files
    () => import('#start/scheduler'),
  ],
})
The provider is configured to run in the console environment by default. This means it only loads when running Ace commands, not during HTTP requests.
3

Review the starter file

The installation creates a start/scheduler.ts file with example schedules:
start/scheduler.ts
import scheduler from 'adonisjs-scheduler/services/main'

scheduler.command("inspire").everyFiveSeconds()

scheduler.call(() => {
    console.log("Pruge DB!")
}).weekly()
You can modify this file to add your own scheduled tasks.
4

Test the installation

Verify the installation by running the scheduler:
node ace scheduler:run
You should see the example inspire command running every five seconds.
Press Ctrl+C to stop the scheduler when you’re done testing.

Available commands

After installation, you’ll have access to the following scheduler commands:
node ace scheduler:run

Manual installation

If you prefer to install manually or need more control over the configuration:
1

Install the package

npm install adonisjs-scheduler
2

Configure the provider

Add the provider to your adonisrc.ts:
adonisrc.ts
providers: [
  {
    file: () => import('adonisjs-scheduler/scheduler_provider'),
    environment: ['console'],
  },
]
3

Register commands

Add the scheduler commands to your adonisrc.ts:
adonisrc.ts
commands: [
  () => import('adonisjs-scheduler/commands'),
]
4

Create scheduler file

Create a start/scheduler.ts file:
start/scheduler.ts
import scheduler from 'adonisjs-scheduler/services/main'

// Add your schedules here
5

Add preload file

Register the scheduler file in your adonisrc.ts:
adonisrc.ts
preloads: [
  () => import('#start/scheduler'),
]

Environment configuration

By default, the scheduler provider runs only in the console environment. If you need to run the scheduler in other environments (e.g., web, test), modify the provider configuration:
adonisrc.ts
providers: [
  {
    file: () => import('adonisjs-scheduler/scheduler_provider'),
    environment: ['console', 'web'], // Add more environments
  },
]

// Or enable for all environments:
providers: [
  () => import('adonisjs-scheduler/scheduler_provider'),
]
Be cautious when enabling the scheduler in the web environment. This will load scheduled tasks during HTTP requests, which may not be desired.

Next steps

Quickstart

Now that you have AdonisJS Scheduler installed, learn how to create your first scheduled task

Build docs developers (and LLMs) love