Queue
Defining a job
bash
php hexaphp make:job ProcessBookingJobphp
use HexaGen\Core\Queue\Job;
class ProcessBookingJob extends Job
{
public function __construct(private Booking $booking) {}
public function handle(): void
{
// send confirmation email, update inventory, etc.
Mail::to($this->booking->email)->send(new BookingConfirmedMail($this->booking));
}
}Dispatching
php
dispatch(new ProcessBookingJob($booking));
dispatch(new ProcessBookingJob($booking))->onQueue('bookings');
dispatch(new ProcessBookingJob($booking))->delay(60); // delay 60 secondsRunning the worker
bash
php hexaphp queue:work
php hexaphp queue:work --queue=bookings
php hexaphp queue:work --queue=bookings,defaultFailed jobs
bash
php hexaphp queue:failed # list failed jobsDrivers
ini
QUEUE_DRIVER=sync # runs inline, no worker needed (dev)
QUEUE_DRIVER=database # stored in jobs table
QUEUE_DRIVER=redisFor the database driver, install the table first:
bash
php hexaphp queue:install
php hexaphp migrate