我正在使用Laravel数据库队列,并且在队列作业处理程序中,我从数据库中获取了无效的结果。
$order->status = "confirmed";
$this->orderRepository->save($order);
logger('Order status before adding to queue: ' . $order->status);
PushToXyz::dispatch($orderId);
class PushToXyz implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @var int
*/
protected $order_id;
/**
* Create a new job instance.
*
* @param int $order_id
*/
public function __construct(int $order_id)
{
$this->order_id = $order_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
app(XyzService::class)->push($this->order_id);
}
}
class XyzService
{
public function push(int $order_id) {
$order = $this->orderRepo->get($order_id);
logger('Order status in job handler: ' . $order->status);
}
}
我希望记录器的输出为:
Order status before adding to queue: confirmed
Order status in job handler: confirmed
但是我得到了
Order status before adding to queue: confirmed
Order status in job handler: new_order
我已经检查了数据库,状态是否正确保存在数据库中。