延迟任务关闭订单,立即执行了?
部署多台服务器之后,延迟关闭订单的任务,会立即执行,在本地是正常的,这里不太明白哪里出了问题?
线上日志:
[2019-01-31 15:12:48] production.DEBUG: order_ttl [1800]
[2019-01-31 15:12:48] production.DEBUG: order_ttl_close {"address":{"address":"河北省 澳门 巫 Street 沈阳城东区","zip":56300,"contact_name":"卓宁","contact_phone":"13211670592"},"remark":null,"total_amount":7029,"type":"normal","user_id":11,"no":"20190131151248787931","updated_at":"2019-01-31 15:12:48","created_at":"2019-01-31 15:12:48","id":1110,"user":{"id":11,"name":"裴晧","phone":"13031617972","email":"atque.aperiam@example.com","is_email_verified":1,"created_at":"2019-01-28 10:37:47","updated_at":"2019-01-28 10:37:47"}}
[2019-01-31 15:12:48] production.DEBUG: order_ttl_delay [1800]
[2019-01-31 15:12:48] production.DEBUG: this close [1]
调试代码:
public function __construct(Order $order, $delay)
{
\Log::debug('order_ttl_close', $order->toArray());
\Log::debug('order_ttl_delay', [$delay]);
$this->order = $order;
$this->delay = $delay;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if ($this->order->paid_at) {
return;
}
\DB::transaction(function () {
\Log::debug('this close', [1]);
$this->order->update(['closed' => true]);
foreach ($this->order->items as $item) {
$item->productSku->addStock($item->amount);
}
if ($this->order->couponCode) {
$this->order->couponCode->changeUsed(false);
}
});
}
推荐文章: