mardi 6 septembre 2016

How to run a Laravel Job at specify Queue

I have a Job to perform send SMS to user. I want to run this job on the specify queue-name. For example, this job added to "SMS" queue. So I found a way to do this but it's exists some errors.

Create job instance and use onQueue() function to do this:

    $resetPasswordJob = new SendGeneratedPasswordResetCode(app()->make(ICodeNotifier::class), [
        'number' => $user->getMobileNumber(),
        'operationCode' => $operationCode
    ]);

    $resetPasswordJob->onQueue('SMS');

    $this->dispatch($resetPasswordJob);

My Job class like this:

class SendGeneratedPasswordResetCode implements ShouldQueue
{
   use InteractsWithQueue, Queueable;

/**
 * The code notifier implementation.
 *
 * @var ICodeNotifier
 */
protected $codeNotifier;

/**
 * Create the event listener.
 *
 * @param ICodeNotifier $codeNotifier
 * @return self
 */
public function __construct(ICodeNotifier $codeNotifier)
{
    $this->codeNotifier = $codeNotifier;
}

/**
 * Handle the event.
 *
 * @return void
 */
public function handle()
{
    echo "bla blaa bla";
    #$this->codeNotifier->notify($event->contact->getMobileNumber(), $event->code);
}

public function failed()
{
    var_dump("failll");
}
}

So I type this command to console:

php artisan queue:listen --queue=SMS --tries=1

But this error message I get when executes this job:

[InvalidArgumentException]

No handler registered for command [App\Services\Auth\User\Password\SendGeneratedPasswordResetCode]

Note: Other way is add event to EventServiceProvider's listen property and fire the event. But it's does not work with specify queue-name.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire