spatie/laravel-queueable-action
Add simple queue support to Laravel “actions.” Call actions synchronously or dispatch them to the queue with $action->onQueue()->execute(), optionally choosing a queue name. Includes a configurable job class for customization.
Queue facade and job architecture. This reduces cognitive overhead for developers already familiar with Laravel’s job system.onQueue()) to enable queuing, reducing integration effort. No need to manually implement ShouldQueue or Dispatchable interfaces.high, default, low) or dedicated queues for specific action types.spatie/laravel-action package (v2.0+), adding a minor dependency but ensuring consistency with Spatie’s design patterns.actions-{type}, {module}-actions)spatie/laravel-action (v2.0+). Ensure the base package is installed and configured.pest for testing) may exist in development.spatie/laravel-action.// Before: Inline logic in controllers
public function updateProfile(Request $request) {
$user->update($request->validated());
}
// After: Action class
class UpdateProfile implements Action {
public function handle(User $user, array $data) {
$user->update($data);
}
}
composer require spatie/laravel-queueable-action.config/queueable-actions.php).$action = new UpdateProfile($user, $data);
$action->onQueue('profiles')->execute(); // Queued execution
high-priority-actions, user-actions).php artisan queue:work --queue=profiles).withMiddleware() method, enabling cross-cutting concerns (e.g., auth, logging).queue:work processes) for high-volume queues.BatchAction from Spatie).queue:work --timeout=120 --memory=256.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Queue worker crashes | Actions not processed | Supervisor (e.g., supervisord) for process management. |
| Database queue connection issues | Jobs stuck in queue | Use Redis for high availability. |
| Action throws unhandled exception | Job fails silently | Implement failed() method in actions or use Laravel’s FailedJob events. |
| Queue overflow | New actions delayed | Implement circuit breakers or rate limiting. |
| Long-running actions | Worker timeouts | Optimize actions or increase worker timeout. |
| Dependency failures (e.g., API) | Action retries indefinitely | Add exponential backoff or max retry limits. |
// Queue an action with custom queue and retry logic
$action->onQueue('high-priority')
->retryUntil(3)
->execute();
How can I help you explore Laravel packages today?