Мне нужно преобразовать полезные данные в форматированную строку.
Это полезные данные из таблицы Fail_jobs:Необработанные полезные данные, полученные из таблицы Failed_jobs:
Код: Выделить всё
{"retries":5,"data":{"command":"O:23:\"App\\Jobs\\SearchForEvent\":11:{s:8:\"\u0000*\u0000alert\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:16:\"App\\Models\\Alert\";s:2:\"id\";i:1;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:12:\"\u0000*\u0000startDate\";N;s:10:\"\u0000*\u0000endDate\";N;s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}","commandName":"App\\Jobs\\SearchForEvent"},"maxTries":null,"attempts":0,"uuid":"44543b2d-d724-443f-b1b9-8cd4c6eb9d6c","timeout":null,"tags":["App\\Models\\Alert:1"],"id":"44543b2d-d724-443f-b1b9-8cd4c6eb9d6c","retry_of":"5e268070-b783-419a-b111-313db95a8cf9","displayName":"App\\Jobs\\SearchForEvent","job":"Illuminate\\Queue\\CallQueuedHandler@call","type":"job","pushedAt":"1617265554.6785","retryUntil":null,"maxExceptions":null,"delay":null,"timeoutAt":null}
Полезная нагрузка:
Код: Выделить всё
retries: 5
data:
command:
{
alert: {
class: "App\Models\Alert",
id: 1,
relations: [
],
connection: "mysql"
},
startDate: null,
endDate: null,
job: null,
connection: null,
queue: null,
chainConnection: null,
chainQueue: null,
delay: null,
middleware: [
],
chained: [
]
}
commandName: App\Jobs\SearchForEvent
maxTries:
attempts: 0
uuid: 44543b2d-d724-443f-b1b9-8cd4c6eb9d6c
timeout:
tags:
0: App\Models\Alert:1
id: 44543b2d-d724-443f-b1b9-8cd4c6eb9d6c
retry_of: 5e268070-b783-419a-b111-313db95a8cf9
displayName: App\Jobs\SearchForEvent
job: Illuminate\Queue\CallQueuedHandler@call
type: job
pushedAt: 1617265554.6785
retryUntil:
maxExceptions:
delay:
timeoutAt:
Код: Выделить всё
public function findFailedJob(int $id): void
{
$this->failedJobObj = $this->model->find($id);
$this->rawPayload = $this->failedJobObj->payload;
$payloadArray = json_decode($this->failedJobObj->payload, 1);
$this->manageCommand();
$this->makeHumanReadablePayload($payloadArray);
}
Код: Выделить всё
private function manageCommand()
{
$payload = json_decode($this->failedJobObj->payload, true);
if (! isset($payload['data']['command'])) {
return '';
}
$str = str_replace('\u0000', ' ', $payload['data']['command']);
$unserialized = unserialize($str, ['allowed_classes' => false]);
$this->command = print_r($unserialized, 1);
}
Команда:
Код: Выделить всё
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => App\Jobs\SearchForEvent
[alert:protected] => __PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => Illuminate\Contracts\Database\ModelIdentifier
[class] => App\Models\Alert
[id] => 1
[relations] => Array
(
)
[connection] => mysql
)
[startDate:protected] =>
[endDate:protected] =>
[job] =>
[connection] =>
[queue] =>
[chainConnection] =>
[chainQueue] =>
[delay] =>
[middleware] => Array
(
)
[chained] => Array
(
)
)
Заранее спасибо!
введите здесь описание изображения
Подробнее здесь: https://stackoverflow.com/questions/669 ... failed-job