英文:
How to dispatch a Laravel job using tinker to a specific queue?
问题
尝试掌握我的Laravel队列。我有一个使用Redis队列由Horizon管理的生产Laravel站点。有一个名为'default'的队列用于基本作业,另一个名为'long-running-queue'的队列具有较长的超时时间。
我的一些较长的作业通过调度程序在'long-running-queue'上在夜间运行,这运行得很可靠。
但有时我需要在白天重新运行这些较长的作业。我已经找出了如何在Tinker(php artisan tinker)中使用\Bus::dispatch()来执行快速作业,但似乎无法将它们分发到长时间运行的队列;它们始终保留在默认队列。
似乎从Tinker控制台执行类似以下的操作应该有效:
\Bus::dispatch(new \App\Jobs\MyJob('MyArg'))->onQueue('long-running-queue')
...但它会报错如下:
PHP错误:在/home/mywebappeval()的第1行调用字符串上的onQueue()成员函数
似乎无法在任何地方找到此问题的已发布解决方案。有什么想法吗?谢谢!
英文:
Trying to master my Laravel queues. I've got a production Laravel site using Redis queues managed by Horizon. There's one queue called 'default' for basic jobs, and another called 'long-running-queue' with a longer timeout.
Some of my longer jobs run via the scheduler overnight on the 'long-running-queue', which works reliably.
But sometimes I need to re-run these longer jobs during the day. I've figured out how to do this for quick jobs using \Bus::dispatch() from tinker (php artisan tinker), but cannot seem to dispatch them to the long-running-queue; they always stay on the default.
It seems that something like this should work from the Tinker console:
\Bus::dispatch(new \App\Jobs\MyJob('MyArg'))->onQueue('long-running-queue')
...but it gives this:
PHP Error: Call to a member function onQueue() on string in /home/mywebappeval()'d code on line 1
Can't seem to fine a posted solution to this problem anywhere. Any ideas? Thanks!!
答案1
得分: 2
你需要调用作业实例的 onQueue()
方法,而你正在调用它在 dispatch
方法的结果上。
$job = (new \App\Jobs\MyJob('MyArg'))->onQueue('long-running-queue');
Bus::dispatch($job);
英文:
You need to call onQueue()
of the instance of the job, you are calling it on the result of the dispatch method.
$job = (new \App\Jobs\MyJob('MyArg'))->onQueue('long-running-queue');
Bus::dispatch($job);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论