Skip to main content
AdonisJS Scheduler is a task scheduler for AdonisJS v6 that allows you to schedule commands and callbacks to run at specific times or intervals. Built on top of node-cron, it provides a fluent API for defining scheduled tasks in your application.

Why use AdonisJS Scheduler?

Scheduling tasks is a common requirement in modern web applications. Whether you need to send daily reports, clean up old records, or run periodic maintenance tasks, AdonisJS Scheduler makes it simple and intuitive.

Key features

Fluent API

Define schedules using an expressive, chainable API that’s easy to read and maintain

Multiple schedule types

Schedule both Ace commands and custom callback functions

Decorator support

Use the @schedule decorator to define schedules directly on your commands

Overlap prevention

Prevent tasks from running concurrently with built-in overlap protection

Timezone support

Run tasks in specific timezones with the .timezone() method

Hot reload

Automatically restart the scheduler when files change during development

Tagging

Organize and selectively run schedules using tags

Lifecycle hooks

Execute code before and after scheduled tasks with .before() and .after() callbacks

Schedule frequency options

AdonisJS Scheduler supports a wide range of scheduling frequencies:
  • Seconds: .everySecond(), .everyFiveSeconds(), .everyTenSeconds()
  • Minutes: .everyMinute(), .everyFiveMinutes(), .everyThirtyMinutes()
  • Hours: .hourly(), .everyTwoHours(), .everyFourHours()
  • Days: .daily(), .weekdays(), .weekends()
  • Weeks: .weekly(), .mondays(), .tuesdays(), etc.
  • Months: .monthly(), .twiceMonthly(), .lastDayOfMonth()
  • Custom: .cron('* * * * *') for custom cron expressions

Example usage

Here’s a quick preview of what scheduling tasks looks like:
start/scheduler.ts
import scheduler from 'adonisjs-scheduler/services/main'
import PurgeUsers from '#commands/purge_users'

// Schedule an Ace command
scheduler.command('inspire').everyFiveSeconds()

// Schedule a command with arguments and prevent overlapping
scheduler.command(PurgeUsers, ['30 days'])
  .daily()
  .withoutOverlapping()

// Schedule a callback function
scheduler.call(() => {
  console.log('Running cleanup task!')
}).weekly()

Next steps

Installation

Install and configure AdonisJS Scheduler in your project

Quickstart

Create your first scheduled task in minutes
For AdonisJS v5, use the 0.x branch of the package.

Build docs developers (and LLMs) love