Laravel 13.x: Jobs können auf Worker-Signale reagieren
Das neue Interface Interruptible erlaubt laufenden Jobs, bei einem SIGTERM des Queue-Workers etwa Schleifen zu stoppen, Locks freizugeben oder den Zustand zu sichern.
Pull request by @jackbayliss
When a queue worker receives a SIGTERM during a deployment, any running job normally has no idea it's about to be cut off. The new Interruptible interface lets jobs react - stop loops, release locks, save state - before the worker shuts down.
use Illuminate\Contracts\Queue\Interruptible;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class SignalJob implements ShouldQueue, Interruptible
{
use Queueable;
protected bool $stop = false;
public function handle(): void
{
while (!$this->stop) {
sleep(1);
// Do work...
}
}
public function interrupted(int $signal): void
{
$this->stop = true;
}
}