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?
For Laravel 5.2:
Queue::after(function (JobProcessed $event) {
$command = unserialize($event->data['data']['command']);
});
The data is serialized. You only have to:$command = unserialize($data['data']['command']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With