Tuesday, March 21, 2017

Laravel command executed in loop

Are there any specific reasons for a command App/Console/Commands/ImportSecond.php to be executed in loop ?

It is launched at the end of the script of the job App/Jobs/ImportFirst.php :

public function handle()
{ 
    $file = $this->file;

    $extension = \File::extension($file);
    $name = \File::name($file);

    $lors = \DB::table('settings')
            ->where('parameter', 'mb_mode')
            ->first();

    if($lors->value == 'seg') {
           \Artisan::call('import:second', ["bid" => $bid, 'filename' => "$name.$extension"]);
    } 
}

The job itself is called by inject_file method from BController.php :

public function inject_file($bid)
{
     $name = \Input::file('file')->getClientOriginalName(); 
     \Input::file('file')->move(storage_path() . '/bids/', $name); 
     $this->dispatch (new ImportFirst($bid, \Input::file('file')->getClientOriginalName())); 
     return "OK";
}

To sum up : BController.php dispatch ImportFirst job to Redis, which launch ImportSecond at last

BController.php -> ImportFirst (job) -> ImportSecond (command)

Laravel version : 5.1.26 - Queue driver : Redis



via Adeline Mani-Rajan

Advertisement