在 Laravel 5.1 中完成后如何捕获作业队列详细信息?
在 Laravel 5.1 中,我希望在作业完成时收到通知,以及有关作业的详细信息(特别是 user_id
和 customer_id
).我在 AppServiceProvider
中使用 Queue::after
方法方法作为 Laravel 建议.
In Laravel 5.1, I would like to be notified when a job is completed, with details about the job (specifically, the user_id
, and customer_id
). I'm using the Queue::after
method method in the AppServiceProvider
as Laravel suggests.
如果像这样转储 $data
参数:
If a dump the $data
parameter like so:
Queue::after(function ($connection, $job, $data) {
var_dump($data);
exit;
});
我得到以下信息:
array(2) { ["job"]=> string(39) "IlluminateQueueCallQueuedHandler@call" ["data"]=> array(1) { ["command"]=> string(263) "O:23:"AppJobsExportContacts":4:{s:7:"*data";a:5:{s:7:"user_id";s:1:"2";s:10:"customer_id";s:1:"1";s:6:"filter";N;s:5:"dates";a:2:{i:0;i:1445352975;i:1;i:1448034975;}s:4:"file";s:31:"/tend_10-20-2015-11-20-2015.csv";}s:5:"queue";N;s:5:"delay";N;s:6:"*job";N;}" } }
data
数组包含我所追求的 user_id
和 customer_id
.这是伟大的.但是我如何解析这个响应来提取这些信息.
The data
array contains both of the user_id
and the customer_id
that I'm after. Which is great. But how do I parse this response to pull that information out.
我唯一的想法是使用正则表达式.但我想我会检查一下是否有更好的方法?
My only thought is to use regex. But I thought I'd check to see if there was a better way?
推荐答案
对于 Laravel 5.2:
For Laravel 5.2:
Queue::after(function (JobProcessed $event) {
$command = unserialize($event->data['data']['command']);
});
相关文章