We are running our production system on Elastic Beanstalk. We want to be able to take advantage of EBS' worker tiers with autoscaling. Unfortunately, due to how Laravel queue processing works, Laravel expects all queues to be consumed by starting a php command line process on your servers. EBS worker tiers don't function that way. AWS installs a listener daemon of its own, that pulls of jobs and feeds them to your worker over local HTTP calls. Sounds great. Unfortunately, I can't figure out how one would call a queued job from a route and controller in Laravel instead of using the built-in artisan queue listener task. Any clues as to how to achieve this would be greatly appreciated.
Can I trigger Laravel jobs from a controller instead of using the `php artisan queue` process
Asked Answered
You can use the Artisan::call
method to call commands from code.
$exitCode = Artisan::call('queue:work');
You can see more info in the docs
I am not trying to call the artisan task. I am trying to process the jobs. –
Nuptials
But won't calling the artisan take still process your jobs? You can put that code in the controller that AWS will call. –
Gauleiter
Hmmmm. Didn't realize that. I am willing to give it a whirl. :-) –
Nuptials
In Controller action method:
JobClassName::dispatch();
The question was about how to trigger the processing of queue jobs via HTTP requests not dispatching jobs –
Chirr
To process queue jobs that are triggered via HTTP controller, you have to call Worker::process()
from your controller with the Job object as an argument.
You could see example in this Laravel package, or you could just install and use that package to achieve same results
© 2022 - 2024 — McMap. All rights reserved.
shell_exec
? – Marinemarinellishell_exec
,eval
and the like because it makes code harder to debug and more prone to security issues. Also it can cause portability issues if you want to run your code on multiple OS types. (not that OP is, just something to keep in mind) – Gauleiter