在Laravel 5.5中,在将作业分配到作业队列后,如何获取作业ID? [英] In Laravel 5.5, how to get the Job ID after we dispatch a job to the job queue?
本文介绍了在Laravel 5.5中,在将作业分配到作业队列后,如何获取作业ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
直到Laravel 5.4,dispatch()
方法返回队列作业ID.
Until Laravel 5.4, the dispatch()
method returned the queue job id.
$job = (new JobClass())->onQueue('queuename');
$jobId = dispatch($job);
dd($jobId); // prints the job id
在5.5中,它返回一个PendingDispatch
对象,该对象似乎没有用于检索作业ID的方法.
In 5.5, it returns a PendingDispatch
object, which does not seem to have a method to retrieve the job id.
我已经尝试使用dispatch_now()
,但是它希望立即在后台执行作业,而我希望在后台执行.
I've already tried with dispatch_now()
, but it executes the job immediately and synchronously, while I want it to be executed in the background.
推荐答案
在Laravel github上发布问题后,解决方案是使用:
After opening an issue at Laravel github, the solution was to use:
app(\Illuminate\Contracts\Bus\Dispatcher::class)->dispatch($job)
代替
dispatch($job)
这篇关于在Laravel 5.5中,在将作业分配到作业队列后,如何获取作业ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文