同步调度工作如何?

时间:2019-04-15 06:44:09

标签: php laravel-5 queue jobs

我正在使用laravel 5.8开发一个多租户应用程序,并且我正在使用this来为该工作设置相关的租户ID,但是当我从这样的控制台分派工作时

$websites = \Hyn\Tenancy\Models\Website::all();
        foreach ($websites as $website) {
            $environment = $this->app->make(\Hyn\Tenancy\Environment::class);
           $environment->tenant($website);

            $schedule->call(function() use ($website){Bus::dispatch((new FetchCallsData()));})->hourly();
}

,在buildDatabaseRecord中,当我尝试获取当前网站时,我将拥有foreach中的最后一个网站。我发现buildDatabaseRecord将通过事件异步运行,因此当前网站在buildDatabaseRecord

中是错误的
protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0)
    {
        $queueRecord = [
            'queue' => $queue,
            'attempts' => $attempts,
            'reserved_at' => null,
            'available_at' => $availableAt,
            'created_at' => $this->currentTime(),
            'payload' => $payload,
        ];
        $website   = app(\Hyn\Tenancy\Environment::class)->tenant();
        //here is the issue and I get last website in foreach loop for all jobs 
         $queueRecord['tenant_id']=$website->id
        //also I tried using global variables but same result 
      /*if(isset( $_SERVER['tenant_id']))
            $queueRecord['tenant_id'] = $_SERVER['tenant_id'];*/


        return $queueRecord;
    }

我认为我需要在工作中添加onTenant($website)或类似的内容?

0 个答案:

没有答案