Laravel 5.8 background job is not in the background

Viewed 557

I have a library, which imports lots of images and I am trying to use Laravel background jobs. For queued jobs, I am following Laravel documentation.

First (create table):

php artisan queue:table
php artisan migrate

Then configuration in .env file for Redis:

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=43216

Create a job:

php artisan make:job CarsJob

CarsJob:

public function handle() 
{
    $cars = new CarsLibrary();
    $CarsLibrary->importAll();
}

Dispatching a job in a some action in the controller:

First what I have tried:

$importCarsJob = (new ImportCarsJob())->onQueue('import_cars');
$this->dispatch($importCarsJob );

Second what I have tried:

$importCarsJob = new importCarsJob();
$this->dispatch($importCarsJob);

I have enabled Redis in my hosting. It is shared hosting.

If I access the URL, I see that this job is not in the background, because it needs more than a minute to finish the request.

EDIT: The env file is above, this is config/queue.php:

    'connections' => [

    'sync' => [
        'driver' => 'redis',
    ],
    ... other drivers like beanstalkd

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],


    'redis' => [
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => 90,
        'block_for' => null,
    ],

],
  • I have no REDIS_QUEUE in env file.
1 Answers

It seems that you have not updated your queue connection in config/queue.php from sync to redis (or the environment variable QUEUE_CONNECTION). The sync driver will execute jobs immediately without pushing them on a queue.

By the way, you don't need the queue database table if you use the redis queue driver.

Related