horizon: Timeout for long running task
Hi,
I have a task that will take a few minutes to complete. I’ve already set the retry_after value in the config/queue.php to 3600 but my task is still canceled after 60 seconds.
I don’t get an error message or something like this. The task just stops working after 60 seconds and keeps marked as running in the dashboard.
Is there a way to increase the timeout for a task?
Maybe this issue is related to #254
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 18 (4 by maintainers)
I already found a solution to my problem.
In the
config/horizon.phpfile I created a second supervisor for long running tasks and set the timeout for this supervisor to 900 seconds (15 minutes). Then I created a new queue config with aretry_aftervalue of 1200 seconds (20 minutes). I also configured the supervisor to use this redis queue config.To be more specific my config files now look like this:
config/horizon.php
config/queue.php
With this configuration my long running tasks works. All tasks are will be done within a few (milli)seconds will be processed using the default queue and therefore the default timeout.
@squatto I think your assumption is valid. Check the Laravel Documentation section Connections Vs. Queues:
Also, note that Horizon has a Queue Wait Time Thresholds setting called
waitsinconfig/horizon.phpwhere it says:As I understand it:
connections(like Amazon SQS, Beanstalk, or Redis)connectionhas at least onequeue, but can also have morequeue workeruses one (and only one)connectionqueue workerworks on at least one (but can be more) of thequeuesthat are associated with theconnectionretry_afteris a parameter for theconnectiontimeoutis a parameter for thequeueretry_aftermust always be larger than thetimeoutIf I define
$timeouton the job Class itself — will it override connection/queue settings?@bilfeldt You can do this using the
onQueue('long-running-queue')method you can call on the result you get from thedispatchmethod.A full example would be
MyDispatchableClass::dispatch($event)->onQueue('long-running-queue').so, basically adding the “timeout” key in horizon.php should be enough
While technically enough, yes, you run the risk of masking problems with your jobs that should run quickly. That’s why it’s good to split them out into your regular queue and your long running queue: long running jobs are given plenty of time to run, and regular jobs still fail if they go beyond the default timeout.
Replying to @bilfeldt:
If I’m understanding this correctly, as he has it configured, his
redisconnection handlesdefaultqueue jobs, and hisredis-long-runningconnection handleslong-running-queuequeue jobs. That’s why you don’t have to specify the connection when you queue the job - you’re specifying a queue that’s only being handled by that specific connection. You would need to specify the connection if you had queues with the same names on both connections. I think 😉 I’m still not 100% sure I grok the connection-vs-queue concept either, especially when you throw Horizon into the mix.