laravel 调度作业仅在调用另一个调度时才会触发。
这是代码:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class SimpleJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $message;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($message = "Default message")
{
$this->message = $message;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Log::info("SimpleJob executed with message: " . $this->message);
echo "SimpleJob executed with message: " . $this->message . "\n";
}
}
当我使用tinker来调试时
dispatch(new App\Jobs\SimpleJob("Delayed Job!"));
直到我下次致电调度时它才完全运行。
使用同步队列驱动程序立即执行
您可以将 QUEUE_CONNECTION 设置为在 .env 文件中同步:
QUEUE_CONNECTION=sync