我可以在拉拉维尔(Laravel)派遣延迟工作
下面的代码不起作用。我认为我已经正确完成了所有事情,但是不知何故我不起作用。
这样的工作是这样派遣的:
MyJob::dispatch($job)->onQueue('processing')->delay(Carbon::now()->addSeconds(30));
myjob.php
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels, Dispatchable;
public function __construct($job)
{
// I described a logging code here and yes, there was change, but then...
}
public function handle()
{
// I described a logging code here, but there wasn't change
}
}
问题是dispatchnow()
确实有效,但是与延迟进行调度无效。
我还正确设置了.env(我猜)
.env文件
QUEUE_CONNECTION=database
config/queue.php
'default' => env('QUEUE_CONNECTION', 'sync'),
The code below doesn't work. I think I have done all things correctly, but somehow I doesn't work.
The job is dispatched like this:
MyJob::dispatch($job)->onQueue('processing')->delay(Carbon::now()->addSeconds(30));
MyJob.php
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels, Dispatchable;
public function __construct($job)
{
// I described a logging code here and yes, there was change, but then...
}
public function handle()
{
// I described a logging code here, but there wasn't change
}
}
The problem is that dispatchNow()
did work, but dispatch with delay didn't work.
I also set .env correctly(I guess)
.env file
QUEUE_CONNECTION=database
config/queue.php
'default' => env('QUEUE_CONNECTION', 'sync'),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
诊断步骤;
打开修补程序并运行
config('queue')
并检查队列设置是否如预期而无需运行队列工作,请将您的工作派遣到队列。打开您的数据库工具,并检查作业表是否包含一个新记录。
使用
php工匠队列运行队列工人:工作
延迟后,作业应运行。检查作业是否从工作表中转到
Diagnostic steps;
Open tinker and run
config('queue')
and check that the queue settings are as expectedWithout running a queue worker, dispatch your job to the queue. Open your database tools and check that the jobs table contains one new record.
run the queue worker with
php artisan queue:work
after the delay, the job should run.Check that the job has gone from the jobs table, and that nothing is in the failed_jobs table.
您可以按照上述建议尝试清除缓存。此外,还要尝试重新启动队列
:工作问题。是的,如果您希望队列永久性主管运行是一个不错的选择。示例配置如下。
You could try clearing your cache as advised above. Additionally, also try to restart the queue
As for the queue:work question. Yes if you want the queue to run permanently supervisor is a good option to use. A sample config is as below.