How should i decode and "prettify" Laravel`s failed-jobs payload?
In my DB in table failed_jobs i have column payload that reads like this:
{"job":"Illuminate\\Queue\\CallQueuedHandler@call","data":{"commandName":"App\\Jobs\\createHostingOncPanel","command":"O:30:\"App\\Jobs\\createHostingOncPanel\":7:{s:10:\"\u0000*\u0000orderNo\";i:11;s:18:\"\u0000*\u0000hostingPackages\";s:45:\"[{\"domainName\":\"qwddqwd.io\",\"hostingType\":1}]\";s:7:\"\u0000*\u0000user\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":2:{s:5:\"class\";s:8:\"App\\User\";s:2:\"id\";i:1;}s:10:\"connection\";N;s:5:\"queue\";N;s:5:\"delay\";N;s:6:\"\u0000*\u0000job\";N;}"}}
Would like to get the string json decoded into something readable.
What kind of format is this? :)
PS: This is a Laravel 5.2 version
Read from failed_jobs table
json_decode the payload from failed_jobs table
$jsonpayload = json_decode($payload);
unserialize the payload command
$data = unserialize($jsonpayload->data->command);
print_r($data);//This is the data passed to queue
I too was having problem as I did not had direct access to production database. I created a route with auth and my controller returned json with all the failed jobs formatted. Here is controller code. With this I was also able to get formatted stack trace of exception due to which job failed
public function getFailedJob()
{
#Fetch all the failed jobs
$jobs = DB::table('failed_jobs')->select()->get();
#Loop through all the failed jobs and format them for json printing
foreach ($jobs as $job) {
$jsonpayload = json_decode($job->payload);
$job->payload = $jsonpayload;
$jsonpayload->data->command = unserialize($jsonpayload->data->command);
$job->exception = explode("\n", $job->exception);
}
return response()->json($jobs);
}
I'd recommend handling the event as-it-happens and then storing any data you need in your own way. You can use Failed Job Events to capture all failed jobs: https://laravel.com/docs/master/queues#failed-job-events
Or you can use the failed()
function on the job itself: https://laravel.com/docs/master/queues#dealing-with-failed-jobs
Otherwise, Marc's comment seems to make sense to me.
try this
$j = App\Models\Jobs::select('payload')->get();
$aw = json_decode($j[0]->payload)->data->command;
$cm = unserialize($aw);
dd($cm->payload);
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