Skip to main content
Kit provides a powerful task scheduling system inspired by Laravel’s scheduler. Schedule tasks to run at specific intervals - every minute, hourly, daily, weekly, or using custom cron expressions.

Generating Tasks

The fastest way to create a new scheduled task is using the Kit CLI:
This command will:
  1. Create src/tasks/cleanup_logs_task.rs with a task stub
  2. Create src/tasks/mod.rs if it doesn’t exist
  3. Create src/schedule.rs for registering tasks
  4. Create src/bin/schedule.rs scheduler binary

Defining Schedules

Kit supports two approaches for defining scheduled tasks: For complex tasks that need dependencies or reusable logic, implement the Task trait and configure the schedule during registration:
Then register with fluent scheduling API in src/schedule.rs:

2. Closure-Based Tasks

For quick, inline tasks without separate files:

Registering Tasks

Register your tasks in src/schedule.rs:

Schedule Frequency Options

Kit provides a fluent API for defining when tasks should run:

Common Intervals

Day-Specific Schedules

Time Modifiers

Chain .at() with any schedule to set a specific time:

Custom Cron Expressions

For full control, use cron syntax:

Task Configuration

Preventing Overlapping

Prevent a task from running if a previous instance is still executing:

Running in Background

Run tasks without waiting for completion:

Running the Scheduler

Kit provides CLI commands for running scheduled tasks:

Run Once

Execute all due tasks once (typically called by cron every minute):

Daemon Mode

Run continuously, checking for due tasks every minute:
This is ideal for development or when using a process manager like systemd.

List Tasks

Display all registered scheduled tasks:
Output:

Run Specific Task

Run a specific task by name:

Production Setup

Using Cron

Add a single cron entry to run the scheduler every minute:

Using Systemd

Create a systemd service for the scheduler daemon:

Accessing App Context

Scheduled tasks have full access to the application context, just like controllers:

File Organization

The recommended file structure for scheduled tasks:
src/tasks/mod.rs:

Summary