spatie/laravel-long-running-tasks
Monitor and manage external long-running tasks (e.g., AWS Rekognition jobs) in Laravel by polling for status. Define a task with a check() method, store metadata, and keep checking at a configurable interval until completion.
check() method is a blank slate for API interactions.long_running_task_log_items table, adding a schema migration. Low risk if the team follows Laravel’s migration practices.StandardBackoffCheckStrategy).check() calls with the same meta data could cause unintended side effects (e.g., duplicate operations). The package doesn’t enforce this; it’s the developer’s responsibility.didNotComplete after keep_checking_for_in_seconds are abandoned. No built-in alerting or escalation (e.g., Slack/email). Requires custom logic (e.g., listening to TaskFailed events).check() are caught and logged but don’t automatically trigger retries unless onFail() returns TaskResult::ContinueChecking. May need additional logic for transient failures (e.g., network blips).queue:work --limit=1) or database-level locking.meta arrays)?status and stop_checking_at for large-scale deployments.TaskStarted, TaskCompleted, TaskFailed) that can be listened to for custom logic (e.g., notifications, analytics).QUEUE_CONNECTION in .env) and workers are running (php artisan queue:work).long_running_task_log_items table.composer require spatie/laravel-long-running-tasks
php artisan vendor:publish --tag="long-running-tasks-migrations"
php artisan vendor:publish --tag="long-running-tasks-config"
php artisan migrate
config/long-running-tasks.php for:
high-priority for critical tasks).StandardBackoffCheckStrategy for exponential retries).Spatie\LongRunningTasks\LongRunningTask.class ProcessPaymentTask extends LongRunningTask {
public function check(LongRunningTaskLogItem $logItem): TaskResult {
$paymentId = $logItem->meta['payment_id'];
$status = PaymentService::checkStatus($paymentId);
return $status === 'completed' ? TaskResult::StopChecking : TaskResult::ContinueChecking;
}
}
ProcessPaymentTask::make()->meta(['payment_id' => 123])->start();
check() to test all status transitions (pending → running → completed/failed).php artisan queue:work --once./etc/supervisor/conf.d/laravel-worker.conf).TaskFailed events).long-running-tasks.php) reduces risk of misconfiguration. Use environment variables for sensitive values (e.g., queue connections).long_running_task_log_items table for stuck tasks:
SELECT * FROM long_running_task_log_items WHERE status = 'running' AND last_check_started_at < NOW() - INTERVAL 1 HOUR;
onFail() to log exceptions to a monitoring system (e.g., Sentry, Laravel Log).check() enters an infinite loop. Add timeouts or circuit breakHow can I help you explore Laravel packages today?