Laravel Job - No handler registered for command

半城伤御伤魂 提交于 2020-01-14 19:05:00

问题


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]".

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

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

Regards.

Update with code:

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);

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


回答1:


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

Try changing this:

class SyncFromJson extends Job implements ShouldQueue

To this:

class SyncFromJson extends Job implements ShouldQueue, SelfHandling



回答2:


I had the exact same problem. In my case it turned out it was the incorrect provider in app config that was the problem. I used a previous project as a framework for my new project and inherited the Laravel collective bus package (That was not required.) The moment I removed the collective bus package ( laravelcollective/bus ) , ran composer update and replaced

Collective\Bus\BusServiceProvider::class,

with

Illuminate\Bus\BusServiceProvider::class,

everything worked fine. This may be a similar issue?



来源:https://stackoverflow.com/questions/38312042/laravel-job-no-handler-registered-for-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!