Menu

Laravel Interruptible Jobs: interrupted(), SIGALRM and horizon:terminate
πŸ“°

Laravel Interruptible Jobs: interrupted(), SIGALRM and horizon:terminate

DEV Community: laravelΒ·laravel-o11yΒ·8 days ago
#SrE1bmzA
#devtolaravel#devto#dev#worker#interrupted
Reading 0:00
15s threshold

When a queue worker is told to stop, Laravel lets the running job finish. For a job that takes four seconds, that is all you need. A job that takes four hours holds the deploy until something runs out of patience and sends SIGKILL , and then it starts again from the top. Since Laravel 13.7 a job can implement Interruptible and hear the signal while it is still running.

The question people ask next is whether that works with horizon:terminate out of the box, or whether you need to check for the stop signal inside your own loop. You get the delivery for free and you write the check yourself. The timeout signal, SIGALRM , follows different rules, and Horizon's autoscaler sends the same SIGTERM as a deploy, which is where the obvious implementation goes wrong.

Key takeaways

horizon:terminate works with no setup. The signal travels from the master through the supervisors to the worker, which calls interrupted(SIGTERM) on the running job.

Your loop still has to check.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.