Laravel 7作业队列句柄方法不工作
我正在尝试使用Laravel7作业队列在延迟一段时间后执行代码。构造函数方法正在工作,但句柄方法不工作。我的代码如下: 控制器:Laravel 7作业队列句柄方法不工作,laravel,laravel-7,laravel-queue,Laravel,Laravel 7,Laravel Queue,我正在尝试使用Laravel7作业队列在延迟一段时间后执行代码。构造函数方法正在工作,但句柄方法不工作。我的代码如下: 控制器: public function test() { echo 'starting ....'; $reset = (new ResetLockers())->delay(now()->addSeconds(10)); dispatch($reset); } class ResetLockers implements ShouldQu
public function test()
{
echo 'starting ....';
$reset = (new ResetLockers())->delay(now()->addSeconds(10));
dispatch($reset);
}
class ResetLockers implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
echo 'constructing ...';
}
public function handle()
{
echo 'job dispatched';
}
}
作业:
public function test()
{
echo 'starting ....';
$reset = (new ResetLockers())->delay(now()->addSeconds(10));
dispatch($reset);
}
class ResetLockers implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
echo 'constructing ...';
}
public function handle()
{
echo 'job dispatched';
}
}
数据库:
public function test()
{
echo 'starting ....';
$reset = (new ResetLockers())->delay(now()->addSeconds(10));
dispatch($reset);
}
class ResetLockers implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
echo 'constructing ...';
}
public function handle()
{
echo 'job dispatched';
}
}
输出:
public function test()
{
echo 'starting ....';
$reset = (new ResetLockers())->delay(now()->addSeconds(10));
dispatch($reset);
}
class ResetLockers implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct()
{
echo 'constructing ...';
}
public function handle()
{
echo 'job dispatched';
}
}
有什么线索吗?我不确定您是如何配置队列的,但是只有当队列正在处理作业时才会调用
handle()
方法。您的代码只是将调度延迟了10秒。在我的.env文件中,我使用QUEUE\u CONNECTION=database并运行php artisan QUEUE:listen database。但是运气不好。试着在handle()中写一些不同的逻辑来确认它是否工作。可能是INSERT语句?有什么线索吗?为什么handle方法不起作用?为什么假设它不起作用?回显“job dispatched”;这段代码在handle方法中不起作用@你希望在哪里看到回声?考虑到队列工作进程与处理web请求的进程是完全独立的