class UpdateUserNameJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
$this->delay(Carbon::now()); // 立即执行
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
User::find(1)->update([
'name' => '22222'
]);
}
}
在 命令行中输入 php artisan tinker || 同时打开一个新的命令窗口, php artisan queue:work 监听队列信息
执行 dispatch(new App\Jobs\UpdateUserNameJob()); 推入到队列中
可以在 队列窗口中 看到[2018-09-27 07:36:56] Processing: App\Jobs\UpdateUserNameJob
[2018-09-27 07:36:56] Processed: App\Jobs\UpdateUserNameJob
vagrant@homestead:~