Update dependencies
Composer: Laravel 13.43, Octane 2.25, Fortify 1.43 and Pest 5.3.7, with the packages they bring (70 in all). This fixes the advisories in Laravel and the Symfony components. npm: Vite 8.3.8 with Rolldown 1.2.19, Playwright 1.65.1 and chokidar 6. The asset build, CI and the dev container use Node.js 26. The dev image also has git for Composer. Both audits are clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Task Scheduling Best Practices
|
||||
# Task scheduling best practices
|
||||
|
||||
## Prevent Unwanted Overlap
|
||||
## Prevent unwanted overlap
|
||||
|
||||
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.
|
||||
Use `withoutOverlapping()` when a second run must not begin while the previous run holds the lock. Use it for variable-duration tasks that are not safe to run concurrently.
|
||||
|
||||
```php
|
||||
Schedule::command('reports:generate')
|
||||
@@ -10,9 +10,9 @@ Schedule::command('reports:generate')
|
||||
->withoutOverlapping(30);
|
||||
```
|
||||
|
||||
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.
|
||||
The optional value is the lock expiration time in minutes, not the task timeout. Choose the value carefully. The default is 24 hours, and an expiration that is too short can permit overlap while the first task still runs. Clear stale locks with `php artisan schedule:clear-cache`. The task itself should still tolerate retries and partial execution where practical.
|
||||
|
||||
## Run a Task on One Server
|
||||
## Run a task on one server
|
||||
|
||||
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`.
|
||||
|
||||
@@ -22,7 +22,7 @@ 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
|
||||
## 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.
|
||||
|
||||
@@ -30,11 +30,11 @@ Tasks due at the same time run sequentially by default. Use `runInBackground()`
|
||||
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.
|
||||
Laravel restricts `runInBackground()` to tasks scheduled with `command()` and `exec()`. It is not available for scheduled closures. Give background processes logging and failure monitoring.
|
||||
|
||||
## Restrict Tasks by Environment
|
||||
## 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.
|
||||
Use `environments()` when a task should run only in named application environments. Treat `environments()` as an operational safeguard, not an authorization control.
|
||||
|
||||
```php
|
||||
Schedule::command('billing:charge')
|
||||
@@ -42,9 +42,9 @@ Schedule::command('billing:charge')
|
||||
->environments(['production']);
|
||||
```
|
||||
|
||||
## Group Shared Configuration
|
||||
## Group shared configuration
|
||||
|
||||
Use schedule groups when several tasks genuinely share frequency or constraints.
|
||||
Use schedule groups when several tasks share frequency or constraints.
|
||||
|
||||
```php
|
||||
Schedule::daily()
|
||||
@@ -56,6 +56,6 @@ Schedule::daily()
|
||||
});
|
||||
```
|
||||
|
||||
## Bound Work Inside the Task
|
||||
## 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