跑
php artisan make:command DispatchJob
创建运行工作的特殊工匠命令.
打开创建的DispatchJob.php文件并定义DispatchJob类,如下所示:
class DispatchJob extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'job:dispatch {job}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Dispatch job';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$class = '\\App\\Jobs\\' . $this->argument('job');
dispatch(new $class());
}
}
现在你应该启动队列工作者:
php artisan queue:work
之后,您可以从命令行运行作业:
php artisan job:dispatch YourJobNameHere