Posts Learn Components Snippets Categories Tags Tools About
/

How to Persist Recent, Pending and Completed Horizon Jobs in Laravel for 24 Hours

Get to know how to extend the duration of the Recent, Pending and Completed Horizon Jobs in Laravel from the default 1 hour to 24 hours or more

Created on Feb 05, 2022

464 views

Laravel Horizon by default has 1 hour "Job Trimming Times" for a successful job which means that after a job has been run the record will remain in the Horizon list for 1 hour and for the failed jobs, it will remain for 7 days.
  • Recent, Pending, Completed = 1 hour
  • Recent Failed, Failed, Monitored - 7 days
This number might be okay for some users but in my case, I need the "Recent, Pending, Completed" to at least remain for 1 day. To have it persist for 1 day you can update the horizon.php configuration and it's located within the trim key.
<?php // horizon.php

// other configs

'trim' => [
    'recent' => 1440, // 1 day
    'pending' => 1440, // 1 day
    'completed' => 1440, // 1 day
    'recent_failed' => 10080, // 1 week
    'failed' => 10080, // 1 week
    'monitored' => 10080, // 1 week
],
Now that you have set it up to the new value, you have to do is to terminate the horizon and then start it once again.
php artisan horizon:terminate

php artisan horizon
I hope you find this useful and cheers, happy coding!

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)