Laravel 5.1完成后如何捕获作业队列详细信息? [英] How to capture job queue details after completion in Laravel 5.1?

查看:318
本文介绍了Laravel 5.1完成后如何捕获作业队列详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 5.1中,我想在作业完成时收到通知,其中包含有关该作业的详细信息(特别是user_idcustomer_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) "Illuminate\Queue\CallQueuedHandler@call" ["data"]=> array(1) { ["command"]=> string(263) "O:23:"App\Jobs\ExportContacts":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_idcustomer_id.太好了但是,我该如何解析此响应以将信息提取出来.

The data array contains both of the user_id and the customer_idthat 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']);
});

这篇关于Laravel 5.1完成后如何捕获作业队列详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆