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.
If a dump the $data
parameter like so:
Queue::after(function ($connection, $job, $data) {
var_dump($data);
exit;
});
I get the following:
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;}" } }
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?
The data is serialized. You only have to:
$command = unserialize($data['data']['command']);
Is there a way to pull the variables that you passed to the job into the queue:after? Did you have to use regex? Even after unserializing its a massive string of data.
Still having trouble extracting data from the job that just ran into queue::after
I think that you do not need to get your data from
data
. I will show you simple use of Queue::laterI hope that i help you
For Laravel 5.2: