I'm trying to use Laravel 5.7 jobs queue to make some insertions/updates in my database and i problably made something wrong because when the job is called its seems to be blocking my application, therefore, not running asynchronously. My code is in the following structure:
.env
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
queue.php
'default' => env('QUEUE_CONNECTION', 'sync'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
job_caller.php
method_name(){
InsereProspeccao::dispatch($path, $evento, $equipe)->onQueue('jobs');
retur some_msg_to_user;
}
job_name.php
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class InsereProspeccao implements ShouldQueue{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $path = '';
private $evento = '';
private $equipe = '';
public function __construct($path, $evento, $equipe){
$this->path = $path;
$this->evento = $evento;
$this->equipe = $equipe;
}
public function handle(){
//all program logic
//access DB for insert/update
}
}
Obs.: I'M READING THE DOCUMENTATION, BUT I CANT FIND WHAT'S GOING WRONG !