账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    laravel 怎么异步执行 自定义Artisan Command
    30
    0

    目前项目中遇到一些耗时比较长的第三方请求,所以想着写一个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这个命令

    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部