简体   繁体   中英

Job which implements ShouldQueue does not write to database

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: []

出于某种原因,.env 文件中的 queue_driver 不受支持,并且当您通过指定它写入数据库的连接来调用调度方法时。

NewJob::dispatch()->onConnection('database');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM