2016-04-06 12 views
4

私はLaravel 5.1を使用しており、キューサービス(Redisドライバ付き)でビルドしています。

キューリスナーは、次のようになります。ジョブ・クラス自体で

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

を私は、応答をチェックした場合に、それは私がキューからではなく、なし、成功したジョブを削除するために$this->delete()を使用肯定応答です、失敗したかどうかに関係なく、ジョブは5回も起動します。

これは私が使用するジョブファイルである:それは起こっているし、それのためのソリューションが何である理由

<?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; 
    } 
} 

誰もが知っていますか?

ありがとうございました! :)

+0

誰ですか?お願いします...? – benjah

答えて

0

イルミネーション\キュー\ InteractsWithQueue;

その後、クラス内

使用をInteractsWithQueue追加します。

これは、あなたがこれらの呼び出し

+0

私はすでにそれを使用しています.../ – benjah

+0

ジョブファイル全体を投稿してください – johnpaulmedina

+0

私は質問メイトを編集しました。 – benjah

0

私は、これは古いスレッドですけど、私は同じ問題に直面したとき、私はコマンドphp artisan queue:listenでキューを開始するのを忘れてbeacuse、それがあったを行うことができます。その後、$this->deleteが働いた。