@d99999

Почему не работает dispatch в Lumen?

Service
В сервисе создаю событие
dispatch(new ProcessWorkableRequest($firstCandidate, $newJob, $jobSearchCandidateDTO))->onQueue(getenv('RABBITMQ_QUEUE'));

//В этот участок кода - lumen даже не заходит, Это понятно по значению в б.д. иначе бы статус изменился
class ProcessWorkableRequest extends Job
{
    private $candidate;
    private $workableService;
    private $stopListCompaniesService;
    private $contractorsService;
    private $jobService;
    private $currentJob;
    private $jobSearchCandidateDTO;

    public function __construct(Candidate $candidate, JobDB $currentJob, JobSearchCandidateDTO $jobSearchCandidateDTO)
    {
        $this->onQueue(getenv('RABBITMQ_QUEUE'));
        $this->candidate = $candidate;
        $this->stopListCompaniesService = app()->make(StopListCompaniesServiceInterface::class);
        $this->contractorsService = app()->make(ContractorsServiceInterface::class);
        $this->workableService = app()->make(WorkableServiceInterface::class);
        $this->jobService = app()->make(JobServiceInterface::class);
        $this->currentJob = $currentJob;
        $this->jobSearchCandidateDTO = $jobSearchCandidateDTO;
    }

    public function handle()
    {
            $workableCandidate = $this->workableService->getDataByUrl($this->currentJob->url);

            if (!$workableCandidate) {
                return [
                    'does_not_exist' => [
                        'label' => 'User does not exist in workable.com',
                        'value' => ''
                    ]
                ];
            }

            $this->currentJob->status = JobDB::STATUSES['IN_PROGRESS'];
            $this->currentJob->save();

            //When we search by candidate name it can be
            $profileUrls = [];
            if (count($this->jobSearchCandidateDTO->candidates) > 1) {
                foreach ($this->jobSearchCandidateDTO->candidates as $candidate) {
                    $profileUrls[] = $candidate->profile_url;
                }
                array_shift($profileUrls);
            }

            $candidate = (new CandidateTransformer)->transform($workableCandidate->candidate);

            $contractor = !empty($candidate->fullname) ? $this->contractorsService->search($candidate->fullname) : [
                'does_not_exist' => [
                    'label' => 'User does not exist',
                    'value' => true
                ]
            ];

            $response = array_merge(
                $candidate,
                $contractor,
                [
                    'search_by' => !empty($candidateFromWorkable) ? $this->jobSearchCandidateDTO->searchedByField : implode(',', CandidateService::SEARCH_BY),
                    'other_candidates_using_current_search_by' => $profileUrls,
                    'is_company_from_stop_list' => $this->stopListCompaniesService->checkIsCompanyInStopList((string)$this->jobSearchCandidateDTO->currentCompany)
                ]
            );

            $this->currentJob->response = \json_encode($response);
            $this->currentJob->status = JobDB::STATUSES['DONE'];
            $this->currentJob->save();
    }
}

Job
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class Job implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
}

queue.php
return [
    'connections' => [
        'rabbitmq' => [
            'driver' => 'rabbitmq',
            'queue' => env('RABBITMQ_QUEUE', 'default'),
            'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
            'hosts' => [
                [
                    'host' => env('RABBITMQ_HOST', 'wl-extension-rabbitmq'),
                    'port' => env('RABBITMQ_PORT', 5772),
                    'user' => env('RABBITMQ_USER', 'wl_user'),
                    'password' => env('RABBITMQ_PASSWORD', 'jh7k56t23h2op'),
                    'vhost' => env('RABBITMQ_VHOST', '/'),
                ],
            ],
            'options' => [
                'ssl_options' => [
                    'cafile' => env('RABBITMQ_SSL_CAFILE', null),
                    'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
                    'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
                    'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
                    'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
                ],
                'queue' => [
                    'job' => VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
                ],
            ],
            'worker' => env('RABBITMQ_WORKER', 'default'),
        ],
        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'workable',
            'retry_after' => 10,
            'block_for' => 5,
        ],
    ]
];
  • Вопрос задан
  • 97 просмотров
Решения вопроса 1
@d99999 Автор вопроса
в app.php добавил
$app->register(VladimirYuldashev\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider::class);
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы