Laravel

Task scheduler

Run Laravel's task scheduler as its own container with php artisan schedule:work. It stays in the foreground and runs schedule:run every minute, so the container needs no cron.

Spin Pro sets up the Laravel scheduler on your own server with zero-downtime deployments.

Compose example

compose.yml
services:
  app:
    image: my-org/my-app:1.0.0
    ports:
      - "80:8080"

  scheduler:
    image: my-org/my-app:1.0.0
    command: ["php", "artisan", "schedule:work"]
    stop_signal: SIGTERM
    healthcheck:
      test: ["CMD", "healthcheck-schedule"]
      start_period: 10s

stop_signal and the health check are required on every worker. Running workers explains why.

Define the schedule in your app

The container only runs the scheduler. Define the tasks in your application, as Laravel's scheduling docs describe:

routes/console.php
<?php

use Illuminate\Support\Facades\Schedule;

Schedule::command('app:process-invoices')
    ->dailyAt('02:00')
    ->timezone('America/Chicago');

Run one scheduler container

Two scheduler containers run every task twice. Keep the scheduler at one replica, or add onOneServer() to each task.

healthcheck-schedule checks that a schedule:work process is running. It doesn't check that tasks succeed.