4

他の API から一部のデータをインポートして保存するキュー ジョブに取り組んでいます。

私のコントローラーから、私が言うと$this->dispatchNow(new ImportPatentsJob($numbers, $count, $invention_id, $redisId));、それはすべて正常に機能し、プロセスは確実に実行されます。

しかし、それを変更してdispatchジョブをキューに入れ、キューワーカーを介して実行すると失敗します。私の仕事は次のようになります。

protected $numbers;
protected $count;
protected $invention_id;
protected $redisId;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($numbers, $count, $invention_id, $redisId)
{
    $this->numbers = $numbers;
    $this->count = $count;
    $this->invention_id = $invention_id;
    $this->redisId = $redisId;

    $this->onQueue('import');
    $this->setUpClients();
}

protected function setUpClients()
{
    $this->imageClient = new Client([
        'base_uri' => 'some-uri',
        'headers'  => ['API-TOKEN' => env('API_TOKEN')],
    ]);

    $this->dataClient = new Client([
        'base_uri' => 'some-uri',
        'headers'  => ['API-TOKEN' => env('API_TOKEN')],
    ]);

    $this->familyClient = new Client([
        'base_uri' => 'some-uri',
        'headers'  => ['API-TOKEN' => env('API_TOKEN')],
    ]);
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    $folder_id = $this->createFolder();

    $currentCount = 0;

    foreach ($this->numbers as $number) {

        $currentCount++;

        Redis::executeRaw(['SET', 'importlog:' . $this->redisId, 'Import ' . $number['number']]);

        try {
            $response = $this->dataClient->get($number['number']); // this is line 85 where the exception occurs
        } catch (\Exception $e) {
            Redis::executeRaw(['SET', 'importlog:' . $this->redisId . ':fail:' . $number['number'], 'Could not import']);
            Log::info($e);
            continue;
        }

        $data = $this->decodeData($response);
        $patent_id = $this->createPatentDocument($data, $folder_id);

        $this->createPatentAddresses($data, $patent_id);
        $this->createPatentApplications($data, $patent_id);
        $this->createPatentPriorities($data, $patent_id);
        $this->createPatentCitations($data, $patent_id);
        $this->createPatentTaxonomies($data, $patent_id);
        $this->createPatentTitles($data, $patent_id);
        $this->createPatentAbstracts($data, $patent_id);
        $this->createPatentClaims($data, $patent_id);
        $this->createPatentDescriptions($data, $patent_id);

        $this->createInventionResults($this->invention_id, $patent_id, $number['position']);

        try {
            $response = $this->imageClient->get($data['bibliographic']['root']['family']);
            $blob = $this->fetchImageBlob($response, $number['number']);
            if ($blob) {
                $this->createFile($blob, $patent_id);
            }
        } catch (\Exception $e) {
            Redis::executeRaw([
                'SET',
                'importlog:' . $this->redisId . ':fail:image:' . $number['number'],
                'Patent number: ' . $number['number'] . '; Family number: ' . $data['bibliographic']['root']['family'],
            ]);
        }

        Redis::executeRaw([
            'SET',
            'importlog:' . $this->redisId . ':progress',
            "Import progress: " . $currentCount . '/' . $this->count . '(' . ($currentCount / $this->count * 100) . '%)'
        ]);
    }
}

Log::info($e)try catch ステートメントで言っている時点で失敗します。例外は次のようになります。

[2016-08-11 07:01:11] local.INFO: exception 'ErrorException' with message 'Undefined property: Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob::$dataClient' in /Users/rohan0793/Code/tenant-application/tenant-package/src/Jobs/ImportPatentsJob.php:85
Stack trace:
#0 /Users/rohan0793/Code/tenant-application/tenant-package/src/Jobs/ImportPatentsJob.php(85): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined prope...', '/Users/rohan079...', 85, Array)
#1 [internal function]: Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob->handle()
#2 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#3 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(82): Illuminate\Container\Container->call(Array)
#4 [internal function]: Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob))
#5 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(150): call_user_func(Object(Closure), Object(Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob))
#6 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob))
#7 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob))
#8 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(83): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#9 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(41): Illuminate\Bus\Dispatcher->dispatchNow(Object(Uppdragshuset\AO\Tenant\Jobs\ImportPatentsJob))
#10 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(130): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#11 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/Jobs/RedisJob.php(50): Illuminate\Queue\Jobs\Job->resolveAndFire(Array)
#12 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(213): Illuminate\Queue\Jobs\RedisJob->fire()
#13 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(157): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), 0, 0)
#14 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(126): Illuminate\Queue\Worker->pop(NULL, 'import', 0, 3, 0)
#15 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(79): Illuminate\Queue\Console\WorkCommand->runWorker(NULL, 'import', 0, 128, false)
#16 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#17 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
#18 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#19 /Users/rohan0793/Code/tenant-application/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /Users/rohan0793/Code/tenant-application/vendor/symfony/console/Application.php(791): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /Users/rohan0793/Code/tenant-application/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /Users/rohan0793/Code/tenant-application/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /Users/rohan0793/Code/tenant-application/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /Users/rohan0793/Code/tenant-application/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 {main}  

プロパティが未定義であると表示されていますが、そのdataClient理由がわかりません。それはかなり定義されており、ジョブがキューに入れられていない場合にうまく機能します。私は何を間違っていますか?

アップデート

そのため、クライアントの保護されたプロパティを宣言するのを忘れていたことに気付きました。しかし、それをするとすぐに、このエラーに遭遇しました。ジョブはキューに入れられなくなりましたが、例外は次のように述べています。Serialization of 'Closure' is not allowed

どういうわけかGuzzleクライアントをシリアライズして保存できないと仮定しています

4

1 に答える 1

3

クロージャをシリアライズできないため、Guzzle クロージャはシリアライズされていませんでした。それが私を捨てていたものです。

例外: 'Closure' のシリアル化は許可されていません

これは、同じ問題を抱えている場合に開始するのに適した場所です。

もっと簡単な方法で解決しました。クライアントの宣言をハンドル メソッド内に移動し、それらをローカル変数にしました。この場合、クライアントをシリアル化する必要はありませんでした。何らかのジョブがそれらを使用するまで、そのままにしておくだけです。

于 2016-08-12T07:48:17.353 に答える