Laravel Job-没有为命令注册的处理程序 [英] Laravel Job - No handler registered for command

查看:104
本文介绍了Laravel Job-没有为命令注册的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一个与Laravel文档中的示例完全相同的简单作业- https://laravel.com/docs/5.2/queues#writing-job-classes -但出现此错误:没有为命令[App \ Jobs \ SendReminderEmail]注册处理程序".

I tried to get a simple job running exactly like the example in the Laravel Documentation - https://laravel.com/docs/5.2/queues#writing-job-classes - but I get this error: "No handler registered for command [App\Jobs\SendReminderEmail]".

我按照说明制作了作业表,甚至是fail_jobs表,并提供了确切的示例代码.

I followed the instructions to make the jobs table and even the failed_jobs table and have the exact example code.

我保证有handle()函数,所以我不知道还有什么可以缺少的.

I assured that the handle() function is there so I don't know what else can be missing.

致谢.

使用代码更新:

首先,我在Laravel示例中使用了该类,但随后将其简化为:

First I used the class in the Laravel example but then I simplified it to this:

<?php

namespace App\Jobs;

use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SyncFromJson extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;

/**
 * Create a new job instance.
 *
 * @return void
 */
 public function __construct()
 {
     //
 }

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    //
    $var = "fooooo";
    \Log::info("job is running!!!", $var);
}
}

要调用该作业,我在调度该作业的控制器中创建了一个简单的方法:

To call the job I created a simple method in a controller that dispatches the job:

$job = (new SyncFromJson())->delay(3);
$this->dispatch($job);

还尝试了以下方法: $this->dispatch(new SyncFromJson());

Also tried this: $this->dispatch(new SyncFromJson());

推荐答案

对于我来说,我有一个类似的问题,实现"SelfHandling"似乎已经解决了该问题.

For what it's worth, I was having a similar problem and implementing 'SelfHandling' seems to have fixed the issue.

尝试更改此内容:

class SyncFromJson extends Job implements ShouldQueue

对此:

class SyncFromJson extends Job implements ShouldQueue, SelfHandling

这篇关于Laravel Job-没有为命令注册的处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆