laravel

时间:2017-12-14 10:08:08

标签: php laravel queue laravel-5.4 multi-tenant

我需要将作业传递给多租户laravel设置中的队列。它与租户连接(租户)一起工作正常,直到工作调度。一旦将作业分派到作业类,它将采用默认连接(pgsql)而不是租户连接(租户)。

这是我的控制器

public function push_queue($ids)
    {
        $params['title']='Test';
        $params['body']='Push Notification Body';
        $params['users_id']=$ids;
        $job = (new PushNotification($params));
        //$this->dispatch($job);
        $connection = \Queue::connection('tenant');
        //dd($connection);
        $connection->pushOn('push', $job);
        //dispatch(new PushNotification($params))->onConnection('tenant')->onQueue('push');
        // $job = (new PushNotification($params))->onQueue('PushNotification');
        // $this->dispatch($job);
        //\Queue::connection('tenant')->push(new PushNotification($params));
        //dispatch(new PushNotification($params));
}

这是我的PushNotification.php作业类文件

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use App\Jobs\PushNotification;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Http\Requests\Request;
use App\Hepclasses\PushNotificationClass;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class PushNotification implements ShouldQueue
{

    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public $connection='tenant';
    protected $params;
    protected $push_notification;
    public function __construct($params)
    {
        $this->params=$params;
        $this->push_notification = new PushNotificationClass();
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        \Log::info(\DB::getDatabaseName());
        $push_result = $this->push_notification->send($this->params);
        return $push_result;
    }
}

0 个答案:

没有答案