Certainly! Here’s a detailed solution addressing your requirements and questions:
1. Packages for Managing Jobs with the database Driver
Unfortunately, there isn't a well-maintained, Horizon-like package for the database queue driver. Most queue monitoring packages (like Horizon) are tightly coupled to Redis for performance reasons. Some alternatives you might want to check (though they may not be as full-featured or actively maintained):
- Laravel Queue Monitor
This package can track jobs for all drivers, includingdatabase. It adds amonitor_jobstable and provides a UI, but you need to add a trait to your jobs. - Laravel Job Viewer
This package provides a simple UI for viewing jobs in thejobsandfailed_jobstables. It’s basic but might fit your needs.
If these don’t fit, your custom solution is a good approach.
2. Doing It the "Laravel Way"
Laravel itself interacts with the jobs and failed_jobs tables using Eloquent and the Illuminate\Queue\DatabaseQueue class. There’s no official UI for the database driver, so your approach is reasonable and aligns with Laravel’s internals.
Key Points for Your Implementation
-
Eloquent Models:
Create models forjobsandfailed_jobstables.// app/Models/Job.php class Job extends Model { protected $table = 'jobs'; protected $casts = [ 'payload' => 'array', ]; } // app/Models/FailedJob.php class FailedJob extends Model { protected $table = 'failed_jobs'; protected $casts = [ 'payload' => 'array', ]; } -
Decoding Payloads:
Thepayloadcolumn is JSON. You can access it as an array if you use$casts. -
Retrying Failed Jobs:
You can use the Artisan command programmatically:Artisan::call('queue:retry', [ 'id' => $failedJobId, ]); -
Displaying Exception:
Theexceptioncolumn infailed_jobscontains the stack trace. -
Querying Awaiting and Failed Jobs:
// Awaiting jobs $awaitingJobs = Job::all(); // Failed jobs $failedJobs = FailedJob::all(); -
Retry from UI:
Create a route/controller that calls the retry logic above.
Sample Controller Snippet
public function retry($id)
{
Artisan::call('queue:retry', ['id' => $id]);
return redirect()->back()->with('status', 'Job retried!');
}
Summary
- There’s no official or widely-used package for database queue monitoring like Horizon.
- Your approach (Eloquent models, decoding payloads, using
queue:retry) is the "Laravel way" for the database driver. - You can use packages like
romanzipp/laravel-queue-monitororimliam/laravel-job-viewerfor a UI, but a custom UI is also perfectly valid. - If you want to dig deeper, look at the
Illuminate\Queue\DatabaseQueueand related classes in Laravel’s source.
If you need code for a simple UI or further help with payload decoding, let me know!