Regenerate Boost guidelines and skills
Generated by boost:update for Boost 2.8, which replaces the pest-testing skill with testing-best-practices and adds infer-conventions. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017XYnWFt9pJEwvAmNFN38XD
This commit is contained in:
co-authored by
Claude Opus 5
parent
3638455167
commit
92b3b3de56
@@ -1,32 +1,50 @@
|
||||
# Task Scheduling Best Practices
|
||||
|
||||
## Use `withoutOverlapping()` on Variable-Duration Tasks
|
||||
## Prevent Unwanted Overlap
|
||||
|
||||
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.
|
||||
Use `withoutOverlapping()` when a second run must not begin while the previous run holds the lock. This is appropriate for variable-duration tasks that are not safe to run concurrently.
|
||||
|
||||
```php
|
||||
Schedule::command('billing:charge')->monthly()->environments(['production']);
|
||||
Schedule::command('reports:generate')
|
||||
->everyFifteenMinutes()
|
||||
->withoutOverlapping(30);
|
||||
```
|
||||
|
||||
## Use `takeUntilTimeout()` for Time-Bounded Processing
|
||||
The optional value is the lock expiration time in minutes, not the task timeout. Choose it carefully: the default is 24 hours, stale locks can be cleared with `php artisan schedule:clear-cache`, and an expiration that is too short can permit overlap while the first task still runs. The task itself should still tolerate retries and partial execution where practical.
|
||||
|
||||
A task running every 15 minutes that processes an unbounded cursor can overlap with the next run. Bound execution time.
|
||||
## Run a Task on One Server
|
||||
|
||||
## Use Schedule Groups for Shared Configuration
|
||||
Use `onOneServer()` when only one scheduler node should run an eligible task. Scheduler nodes must use the same default cache store, and that store must support atomic locks. Supported stores include `database`, `memcached`, `dynamodb`, and `redis`.
|
||||
|
||||
Avoid repeating `->onOneServer()->timezone('America/New_York')` across many tasks.
|
||||
```php
|
||||
Schedule::command('billing:charge')->daily()->onOneServer();
|
||||
```
|
||||
|
||||
Name scheduled closures before applying `onOneServer()`, especially when scheduling the same closure with different parameters, so each task has a distinct lock identity.
|
||||
|
||||
## Run Eligible Commands in the Background
|
||||
|
||||
Tasks due at the same time run sequentially by default. Use `runInBackground()` when an independent, long-running scheduled command should not delay later tasks.
|
||||
|
||||
```php
|
||||
Schedule::command('analytics:process')->hourly()->runInBackground();
|
||||
```
|
||||
|
||||
Laravel restricts `runInBackground()` to tasks scheduled with `command()` and `exec()`; it is not available for scheduled closures. Ensure background processes have appropriate logging and failure monitoring.
|
||||
|
||||
## Restrict Tasks by Environment
|
||||
|
||||
Use `environments()` when a task should run only in named application environments. Treat this as an operational safeguard, not an authorization control.
|
||||
|
||||
```php
|
||||
Schedule::command('billing:charge')
|
||||
->monthly()
|
||||
->environments(['production']);
|
||||
```
|
||||
|
||||
## Group Shared Configuration
|
||||
|
||||
Use schedule groups when several tasks genuinely share frequency or constraints.
|
||||
|
||||
```php
|
||||
Schedule::daily()
|
||||
@@ -37,3 +55,7 @@ Schedule::daily()
|
||||
Schedule::command('emails:prune');
|
||||
});
|
||||
```
|
||||
|
||||
## Bound Work Inside the Task
|
||||
|
||||
The scheduler does not provide a `takeUntilTimeout()` event method or terminate arbitrary tasks at a deadline. Bound work in the command or job itself by processing finite chunks, checking a deadline, or dispatching queue jobs with suitable timeouts. Use operating-system or process controls when hard termination is required.
|
||||
|
||||
Reference in New Issue
Block a user