3

I'm completely new using laravel/lumen

I generate a new lumen proyect a few hours ago and I'm trying to send job to the default queue using a database driver.

my .env file looks like this

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=xxxx

CACHE_DRIVER=file
QUEUE_DRIVER=database

Following the official Queues - Lumen page I generate a migration to create jobs and failed_jobs tables.

config/queue.php file has the default configuration

Problem:

  1. before running the command php artisan queue:work I tried to send a job to the queue, Queue::push(new SendEmailJob) but it run immediately and I didn't run the command php artisan queue:work yet. I check the database and table job is empty.
  2. I run the command php artisan queue:work make a request to a specific endpoint, put the job on the queue using one of this line Queue::push(new SendEmailJob) or dispatch(new SendEmailJob()) I got no errors but jobs queue still empty

What am I doing wrong?

Why queue process all jobs before I run the command php artisan queue:work ?

Thanks in advance

YuryDG
  • 425
  • 3
  • 7

3 Answers3

1
  1. You can dispatch a job and ask for a delay before it is executed:

$this->dispatch((new ProcessJob($id))->delay(10)); // 10 ms

  1. Make sure the worker is not running:

ps aux|grep queue

If so, kill it. Although the best practice is to restart the worker after any code change:

php artisan queue:restart

pamit
  • 326
  • 2
  • 10
0

APP.PHP

if(\Illuminate\Support\Facades\Schema::hasTable("jobs")) Queue::push(new ProcessCenterJob());

0

For me it was the incorrect name for the driver/connection variable in the .env so it was still using sync instead of database. In the .env it was QUEUE_DRIVER but in the queue.php config it was referenced as QUEUE_CONNECTION

Rename the variable in .env to QUEUE_CONNECTION should resolve the issue

Ryan Worth
  • 151
  • 2
  • 9