How to execute Custom Artisan Command asynchronously by laravel

some time-consuming third-party requests are encountered in the current project, so I want to write a command to execute these time-consuming third-party requests asynchronously. The command, is triggered when the user requests the relevant interface and the command is executed asynchronously. At this point, users do not have to wait for the results of command, they can continue to browse.
Code:

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]]);
    }

I would like to ask you guys how you can execute the sync:fba command asynchronously

Sep.16,2021

it is impossible for command to be asynchronous. You can add a queue, call sync:fba in the queue, and then dispatch ((new QueueJob ($param); in logic to push a job, in the queue so that command can be executed asynchronously


class YourCommand extends Command implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    ...
}

refer to https://laravel-china.org/doc.
ordinary events-> queue events, as an example.

Menu