Ensuring Horizon terminates gracefully

Updated: Jan 2, 2020 — 1 min Read#horizon

One of the useful features of Laravel Horizon is its ability to gracefully shutdown, that means it'll wait for any running jobs to finish before the processes are terminated.

However, in order to really guarantee that your jobs won't be interrupted you need to make sure of the following:

  1. Your Horizon supervisors' timeout value is greater than the number of seconds consumed by the longest running job.
  2. Your job-specific timeout is shorter than the timeout value of the Horizon supervisor.
  3. If you're using Supervisor to monitor the Horizon process, make sure the value of stopwaitsecs is greater than the number of seconds consumed by the longest running job.

With this correctly configured, Supervisor will wait for the Horizon process to terminate and won't force-terminate it after stopwaitsecs passes.

Horizon supervisors will also wait for the longest job to finish running and won't force-terminate after the timeout value passes.

By Mohamed Said

Hello! I'm a full-stack web developer working at Laravel. In this publication, I share everything I know about Laravel's core, packages, and tools. You can find me on Twitter and Github. You can also check my blog.

Join Our Mailing List

If you like this article, you may want to consider joining our mailing list to receive new content once it is posted.
This site was built using Wink. Follow the RSS Feed.