I'm trying to implement the basic queue in Laravel 5.7.
I have run the migration which creates the jobs and failed_jobs tables.
I have updated the .env to QUEUE_CONNECTION=database and QUEUE_DRIVER=database
I have created a basic Job with artisan
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class NewJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
sleep(5);
}
}
I'm calling the NewJob in a Controller.
NewJob::dispatch();
I have run the following artisan commands
php artisan config:cache
php artisan cache:clear
php artisan queue:flush
I'm not looking for the queue to execute because the Job isn't writing to the database.
There is no errors in the Larravel.log neither are there any files in /var/log/* that have been modified that I can tail.
I dont know where to look or what to change. I have redone this implementation by redoing the migrations and a new Job called in another controller and I still dont get any data being written to the database.
I'm using Mariadb(InnoDB) on a Debian server.
It looks like the db connection is null
#job: Illuminate\Queue\Jobs\SyncJob {#5458 ▼
#job: null
#payload: "{"displayName":"App\\Jobs\\NewJob","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":null,"timeout":null,"timeoutAt":null,"data":{"commandName":"App\ ▶"
#instance: Illuminate\Queue\CallQueuedHandler {#5470 ▶}
#container: Illuminate\Foundation\Application {#2 ▶}
#deleted: false
#released: false
#failed: false
#connectionName: "sync"
#queue: null
}
connection: null
queue: null
chainConnection: null
chainQueue: null
delay: null
chained: []
CodePudding user response:
For some reason, the queue_driver in the .env file is not honored and when you call the dispatch method by specifying the connection it writes to the db.
NewJob::dispatch()->onConnection('database');