mercredi 6 avril 2016

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

I'm useing Laravel 5.1 and it built in Queue service (with Redis driver).

the queue listener look like this:

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

In the job class itself I check the response and in case it is a positive response I use $this->delete() to remove the job from the queue but with no success, the job still fires 5 times no matter if failed or not.

this is the handle function I uses:

 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{
            $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){
                $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();
                return true;
            }
            throw new \Exception('No response for lead id '.$this->lead->_id.' is breaking the job??');
            return false;
        }
    }else{
        $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;
}

Anyone know why it's happening and what is the solution for it?

Appreciate any help! :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire