繁体   English   中英

Laravel 5.1队列作业$ this-> delete()不起作用

[英]Laravel 5.1 Queue jobs $this->delete() not work

我正在使用Laravel 5.1,它内置于Queue服务(使用Redis驱动程序)。

队列侦听器如下所示:

php artisan queue:listen --tries=5 --delay=60 redis

在作业类本身,我检查响应,如果它是一个肯定的响应,我使用$this->delete()从队列中删除作业但没有成功,无论是否失败,作业仍然会触发5次。

这是我使用的Job文件:

<?php

namespace LM2\Jobs;

use LM2\Http\Controllers\API;
use LM2\Http\Controllers\PredictionsController;
use LM2\Jobs\Job;
use Illuminate\Support\Facades\Log;
use LM2\Http\Controllers\AnalyticsController;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use LM2\Models\Client;
use LM2\Models\GoogleIntegration;
use LM2\Models\Lead;

class CompleteLeadAnalyticsDetails extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    const NUMBER_OF_TRIES = 5;

    private $lead;
    private $client;

    public function __construct(Lead $lead, Client $client)
    {
        $this->lead   = $lead;
        $this->client = $client;
    }

    public function handle(AnalyticsController $analyticsController, API $api,PredictionsController $prediction)
    {
        Log::info("Inside CompleteLeadAnalyticsDetails::handle()");
        $integration = GoogleIntegration::where('client_id', $this->client->id)->first();
        if(count($integration) > 0){
            if($this->attempts() > 1){
                Log::info("CompleteLeadAnalyticsDetails::handle() attempt ".$this->attempts());
                $this->release(120);
                Log::info("CompleteLeadAnalyticsDetails::handle() released");
            }
            try{
                if(count($this->lead->ga_details) > 1){
                    return;
                }
                $res = $analyticsController->getLeadDetails($integration->view_id,$this->lead->ga_details['uacid'],$this->lead->_id,$this->client);
                Log::info("Analytics response: ".$res);
                Log::info('has $res');
                if($res){
                    if(isset($this->lead->email_sent) && (bool)$this->lead->email_sent){
                        return;
                    }else {
                        $prediction->predict($this->lead, $this->client);
                        $api->sendLeadEmail($res, $this->client);
                        $api->forwardToWebService($this->client, $this->lead);
                        Log::info('email sent');
                        $this->delete();
                        return true;
                    }
                }
            }catch (\Exception $e){
                Log::info('no $res, number of attempts:'.$this->attempts()." for lead id:".$this->lead->_id.' number of Attempts: '.$this->attempts());
                if($this->attempts() == self::NUMBER_OF_TRIES){
                    $api->forwardToWebService($this->client,$this->lead);
                    $api->sendLeadEmail($this->lead, $this->client);
                    Log::info('email sent, no $res');
                    $this->delete();
                }
                throw new \Exception('No response for lead id '.$this->lead->_id.' is breaking the job??');
                return false;
            }
        }else{
            if(isset($this->lead->email_sent) && (bool)$this->lead->email_sent){
                return;
            }
            $api->forwardToWebService($this->client,$this->lead);
            $api->sendLeadEmail($this->lead, $this->client);
            Log::info("Client ".$this->client->name.', id:'.$this->client->id.' was not integrate with google CompleteLeadAnalyticsDetails on line:62');
            $this->delete();
        }
        return true;
    }
}

任何人都知道它为什么会发生,它的解决方案是什么?

感谢任何帮助! :)

使用Illuminate \\ Queue \\ InteractsWithQueue;

然后在课堂内添加

使用InteractsWithQueue;

这将允许您拨打这些电话

我知道这是旧线程,但是当我遇到同样的问题时,我忘了用命令php artisan queue:listen来启动队列。 之后, $this->delete工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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