Skip to main content
Version: 2.62.1

Scheduler

This guide explains how to configure and use Platformatic's built-in scheduler. The scheduler allows you to run periodic tasks by making HTTP requests at scheduled intervals using cron expressions. Note that the scheduler is in-memory only, so no information is persisted between restarts.

Overview

The Platformatic scheduler enables you to configure automated HTTP requests that run according to a specified schedule. This feature is useful for:

  • Periodic data synchronization
  • Scheduled maintenance tasks
  • Recurring API calls
  • Implementing workflows that need to run at specific times

Configuration

The scheduler is configured using an array of job definitions in your Platformatic configuration file.

Here's a basic example:

//...
"scheduler": [
{
"name": "my-scheduled-job",
"cron": "*/5 * * * *",
"callbackUrl": "http://localhost:3042/my-endpoint",
"method": "GET"
}
]

//...

Job Configuration Options

Each job in the scheduler can include the following options:

OptionTypeRequiredDescription
nameStringYesA unique identifier for the job
cronStringYesA cron expression defining the schedule
callbackUrlStringYesThe URL to call when the job is triggered
enabledBooleanNo (defaults to true)If false, the job is disabled.
methodStringNo (defaults to 'GET')HTTP method to use (GET, POST, PUT, DELETE)
headersObjectNoHTTP headers to include in the request
bodyString / ObjectNoRequest body (for POST/PUT requests)
maxRetriesNumberNo (defaults to 3)Number of retries attempts

Cron Expression Format

The scheduler uses standard cron expressions with an optional seconds field. Examples:

  • */1 * * * * * - Every second
  • 0 */5 * * * * - Every 5 minutes
  • 0 0 * * * * - Every hour
  • 0 0 12 * * * - Every day at noon
  • 0 0 0 * * 1 - Every Monday at midnight

See crontab.guru for more examples.

Example: call service in the mesh network

It is possible (and useful) to call also services in the platformatic mesh network. Here's an example configuring a job that sends a POST request every minute to an internal notification service (so exposed as http://notification.plt.local in the mesh network).

//...
"scheduler": [
{
"name": "send-message",
"cron": "0 */1 * * * *",
"callbackUrl": "http://notification.plt.local/message",
"method": "POST",
"headers": {
"content-type": "application/json",
},
"body": {
"message": "Scheduled notification",
"type": "info"
}
}
]
//..