2017-01-17 1 views
0

나는 함수에서 여러 작업을하고 난 내가하는 기능 아래와 같이 가지고 예를 들어,이 트랜잭션 작업
에 대한 레디 스 큐를 사용하고자하는 기능
에서 트랜잭션을 사용
핸들 거래

private function check_destination_delivered($request,$id,$order) 
{ 
    if ($request->get('status') == 'destination_delivered') 
    { 
     $this->destination_verification($request); 
     DB::beginTransaction(); 
     try 
     { 
     $this->calculate_credit($id,$order); 
     $this->calculate_customer_gift_credit($id,$order); 
     DB::commit(); 
     } 
     catch (\Exception $e) 
     { 
     DB::rollback(); 
     return $this->respondUnprocessable(1180,'error', $e); 
     } 
    } 
} 
이 기능에

내가이 라인

$this->destination_verification($request); 

트랜잭션 전에 실행 시작이 라인을 한 후 원하는 :

$this->calculate_credit($id,$order); 
    $this->calculate_customer_gift_credit($id,$order); 

사용 레디 스 나중에 몇 시간을 계산하고 수행 할 수있는이 모든 작업에 트랜잭션을 사용하기 위해 대기하고 일부 작업을 다시 실행 .queue 실패 할 경우 모든 작업은 내가하여 문제를 해결

+0

친구를 도와주세요 – amirali

+0

아무도 ........? – amirali

답변

0

할 때까지 아래와 같은 큐에 기능을 넣어 : 모든 작업이 큐 루프가 실행 .IN하지 않으면

다시
그것은 바로
class CreditJob extends Job implements ShouldQueue 
{ 
use InteractsWithQueue, SerializesModels; 

protected $order; 
protected $trip; 
protected $promotion; 
protected $customer; 

public function __construct($order,Order $trip,Customer $customer, Promotion $promotion) 
{ 
    $this->order = $order; 
    $this->trip = $trip; 
    $this->promotion = $promotion; 
    $this->customer = $customer; 
} 

public function handle() 
{ 
    $retry=0; 
    $notDone=TRUE; 
    DB::beginTransaction(); 
    while($notDone && $retry < 5) 
    { 
     try 
     { 
      $this->calculate_promotion($this->order); 
      $this->calculate_credit($this->order); 
      DB::commit(); 
      $notDone=FALSE; 
     } 
     catch (\Exception $e) 
     { 
      DB::rollback(); 
      $retry++; 
      sleep(30); 
     } 
    } 
    if($retry == 5) 
    { 
     $this->trip->fail_calculate_credit_and_promotion($this->order); 
    } 
} 

} 

인가?

+0

아무도 ........? – amirali