Files
fuel-price/.claude/skills/laravel-best-practices/rules/scheduling.md
Ovidiu U ec3ad9130c
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
init
2026-04-04 08:23:04 +01:00

1.3 KiB

Task Scheduling Best Practices

Use withoutOverlapping() on Variable-Duration Tasks

Without it, a long-running task spawns a second instance on the next tick, causing double-processing or resource exhaustion.

Use onOneServer() on Multi-Server Deployments

Without it, every server runs the same task simultaneously. Requires a shared cache driver (Redis, database, Memcached).

Use runInBackground() for Concurrent Long Tasks

By default, tasks at the same tick run sequentially. A slow first task delays all subsequent ones. runInBackground() runs them as separate processes.

Use environments() to Restrict Tasks

Prevent accidental execution of production-only tasks (billing, reporting) on staging.

Schedule::command('billing:charge')->monthly()->environments(['production']);

Use takeUntilTimeout() for Time-Bounded Processing

A task running every 15 minutes that processes an unbounded cursor can overlap with the next run. Bound execution time.

Use Schedule Groups for Shared Configuration

Avoid repeating ->onOneServer()->timezone('America/New_York') across many tasks.

Schedule::daily()
    ->onOneServer()
    ->timezone('America/New_York')
    ->group(function () {
        Schedule::command('emails:send --force');
        Schedule::command('emails:prune');
    });