laravel failed_job 还原

laravel will execute the failed job into failed_job table, payload stores information of job, job in the objects we need to restore analyze the cause of failure.

  1. Tracking the source code found on the job objects are serialized, and then add other parameters json transformation, then we will be doing exactly the opposite
vendor/illuminate/queue/Queue.php:85

json_encode([
                'job' => 'Illuminate\Queue\CallQueuedHandler@call',
                'data' => ['command' => serialize(clone $job)],
            ]);

  1. Failed_job directly to the exterior of the payload assigned to a variable, and then parse the line. It should be noted that the problem escapes the string, which is the reason I use nowdoc way. nowdoc way does not resolve any of the escape character, protects the integrity of json string.
$jobStr = <<<'EOF'
{"job":"Illuminate\\Queue\\CallQueuedHandler@call","data":{"command":"O:19:\"App\\Jobs\\CaseReport\":6:{s:5:\"queue\";s:12:\"cases-report\";s:7:\"\u0000*\u0000case\";i:6369701;s:7:\"\u0000*\u0000pool\";i:20;s:9:\"\u0000*\u0000record\";N;s:6:\"\u0000*\u0000job\";N;s:5:\"delay\";N;}"},"id":"c43gA7efKgVl9TavrqloRBiRY9sD0KeD","attempts":2}
EOF;

$job = json_decode($jobStr,true);
$command = $job['data']['command'];
$obj = unserialize($command);
dd($obj);

Output:

App\Jobs\CaseReport {#116
  +queue: "cases-report"
  #case: 6369701
  #pool: 20
  #record: null
  #job: null
  +delay: null
}

Published 20 original articles · won praise 4 · views 30000 +

Guess you like

Origin blog.csdn.net/Csw_PHPer/article/details/104100667