我在一个函数中有多个任务,我在函数中使用事务
我想将redis队列用于此事务任务
例如,我有如下功能:
$this->destination_verification($request);
在这个功能中我想要这一行
$this->calculate_credit($id,$order);
$this->calculate_customer_gift_credit($id,$order);
在交易开始之前运行,之后运行:
List<BarEntry>
使用redis队列计算几个小时后,将事务用于完成的每个任务,如果某些任务失败,则再次运行,直到完成所有任务
答案 0 :(得分:0)
I fix it by put function in queue like below :
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);
}
}
}
If all the tasks not done .in queue loop running again
Is it right?