Lars-Janssen's avatar

Run shell command in queued job

Hi,

I'm using horizon for my jobs. When I run a shell command in my job:

                exec(env('FFMPEG_PATH').' -i '.$this->file. ' '.$newFileFullPath);

And have horizon running in the background php artisan horizon. I see that the script is executed (i can see it's running for a long time, it's converting a file). However, why am even seeing this? I would only expect to see that a job has dispatched and is running. For example: Processed: App\Jobs\CampaignFileUploadJob . It looks like my exec() command is blocking all other jobs that are dispatched.

Any idea if this is normal and how I can fix this?

0 likes
7 replies
bugsysha's avatar

@sr57 I wouldn't suggest running this in the background, then what is the point of having a queued job?

bugsysha's avatar

@sr57 yes, I understand that. Just wanted to highlight it to the OP so it is clear it is a sub-optimal solution.

bugsysha's avatar

It looks like my exec() command is blocking all other jobs that are dispatched.

That is not what is happening. You've probably configured to run only one job at a time.

Lars-Janssen's avatar

@bugsysha hmm so it's not a bad thing? Is it normal to do it like this if you want to run jobs in sequence?

bugsysha's avatar

@Lars-Janssen I would suggest either dispatching the next job from the current job or using batch jobs or just job chains depending on what you need. Everything is in the docs so I encourage you to read it.

https://laravel.com/docs/9.x/queues

so it's not a bad thing?

It should be considered a bad thing because you have a bottleneck. But it depends on what you need. If this is your own app that will only be used by you and you will never have needs for greater throughput, then you can leave it. In all other cases, I would suggest doing it properly.

Please or to participate in this conversation.