M
M
Morfeey2018-12-19 10:04:51
Laravel
Morfeey, 2018-12-19 10:04:51

Laravel asynchronous work, what am I doing wrong?

There is a certain list of tasks that hung on the crown and run commands:

spoiler
foreach ($Sites as $site) {
            $EveryMethod = $site->frequency_of_removal;
            $schedule
                ->command(RemoverPositions::class, [$site->id])
                ->cron($EveryMethod);
        }

The commands themselves are not really needed, but there is no time for refactoring yet. So the commands should start the worker, but this worker must work asynchronously. In fact, it doesn't even get to the handle method:
command handle
SiteRemoverPositions::dispatch($Site)->onQueue($Site->name);

SiteRemoverPositions worker
<?php

namespace App\Jobs;

use App\Console\Commands\RemovalPositions;
use App\Helpers\RemovalSiteHelper;
use App\Site;
use App\Test;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SiteRemoverPositions implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $site;

    /**
     * Create a new job instance.
     *
     * @param Site $site
     */
    public function __construct(Site $site)
    {
        (new Test(["value" => "constructor job"]))->save();
        $this->site = $site;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        (new Test(["value" => "handle job"]))->save();
        $Site = $this->site;
        (new RemovalSiteHelper($Site))
            ->removal();
    }
}


The worker himself gets into the queue with the specified name in the database, but what to do with him next ??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-12-19
@Sanasol

The worker himself gets into the queue with the specified name in the database, but what to do with him next ??

Probably it is necessary to start a queue so that it processes jobs?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question