1

I have this code on my controller.

// Queue job, Send notification
ExportCsvJob::dispatch(json_encode($exportdata))
    ->onConnection('database')
    ->onQueue('default');

.env file

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

config/queue.php

return [
    'default' => env('QUEUE_DRIVER', 'sync'),

    'connections' => [

        'sync' => [
            'driver' => 'sync',
        ],

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

        'beanstalkd' => [
            'driver' => 'beanstalkd',
            'host' => 'localhost',
            'queue' => 'default',
            'retry_after' => 90,
        ],

        'sqs' => [
            'driver' => 'sqs',
            'key' => 'your-public-key',
            'secret' => 'your-secret-key',
            'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
            'queue' => 'your-queue-name',
            'region' => 'us-east-1',
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'default',
            'retry_after' => 90,
        ],

    ],

    'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],

but when running php artisan queue:work --timeout=3600 never do anything,

I have this two records in jobs table

+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
| id  | queue           | payload                                                                                              | attempts | reserved_at | available_at | created_at |
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+
| 168 | shipment_export | {"displayName":"App\\Jobs\\ExportCsvJob","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries |        0 |        NULL |   1549262600 | 1549262600 |
| 169 | default         | {"displayName":"App\\Jobs\\ExportCsvJob","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries |        0 |        NULL |   1549262834 | 1549262834 |
+-----+-----------------+------------------------------------------------------------------------------------------------------+----------+-------------+--------------+------------+

but when I changed QUEUE_DRIVER=sync to QUEUE_DRIVER=database It worked

Can give me explanation and possibly solution about my problem?

Fil
  • 8,225
  • 14
  • 59
  • 85
  • read more here : https://stackoverflow.com/questions/43467680/laravel-queues-how-sync-driver-works-does-it-executes-in-a-seperated-process – Saurabh Mistry Feb 04 '19 at 06:59
  • You are dispatching jobs to ```->onConnection('database')``` and in ```.env``` default queue_driver set to ```syc``` which is why **queue:work** only looking for jobs at ```sync``` drivier. You can define queue and driver while executing ```queue:work``` command like this ```php artisan queue:work database --queue=default``` – Tamim Feb 04 '19 at 06:59
  • I just found that specifying the connection would solved the problem. https://laravel.com/docs/5.7/queues#running-the-queue-worker – Fil Feb 04 '19 at 08:21
  • I'm pretty sure when you use `sync` driver it executes immediately, you won't need to use `php artisan queue:worker`. – Adis Azhar Feb 04 '19 at 14:59

0 Answers0