目前項目中遇到一些耗時比較長的第三方請求,所以想著寫一個command來異步執行這些耗時的第三方請求。在用戶請求相關接口時觸發command,然后異步執行command。這時用戶不需一直等待command的結果,可以繼續瀏覽。代碼:public function sync(){
$enterId = $this->request->input('enter_id');
$warehouseId = $this->request->input('warehouse_id');
$personId = $this->request->attributes->get('person')->id;
$warehouse = Warehouse::getById($warehouseId, $enterId);
$warehouse->syncValid(); //同步校驗
$commandKey = ['key' => 'SYNC_FBA','enterprise' => $enterId, 'warehouse'=>$warehouseId];
$commandId = CommandLog::getCommand($enterId, $personId, $commandKey);
Artisan::call('sync:fba',[ 'enterprise'=> $enterId, '--warehouse'=> $warehouseId, '--command'=> $commandId, '--help'=>true
]); //執行同步FBA
return $this->response(['data'=>['command_id'=>$commandId]]);
}請問各位大佬,怎樣可以可以異步執行sync:fba這個命令
- 1 回答
- 0 關注
- 3229 瀏覽
添加回答
舉報
0/150
提交
取消