如何在运行队列之前分派作业:work命令 [英] How to dispatch a job before running queue:work command

查看:54
本文介绍了如何在运行队列之前分派作业:work命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让电子邮件通知排队,并且该通知用于登录网站.

I want to make queue for email notifications and this notification is used for logging into website.

因此,在通知文件中,我实现了 ShouldQueue ,然后运行了 php artisan queue:table &在终端上成功完成 php artisan迁移.

So at the notification file I implemented ShouldQueue and then I ran php artisan queue:table & php artisan migrate on terminal successfully.

此后,我将 .env 上的 QUEUE_CONNECTION 更改为数据库,并最终尝试在运行 php后运行 php artisan queue:table 工匠服务,但它完全冻结:

After that I changed QUEUE_CONNECTION on .env to database and finally tried to run php artisan queue:table after runing php artisan serve but it freezes at all:

我什至再次运行了 php artisan config:clear php artisan queue:work ,但仍然冻结!

I even ran php artisan config:clear and php artisan queue:work again but still freezes!

更新:

正如 user1994 所建议的那样,我必须在运行此命令之前调度作业,但是我不知道如何以及在何处调度它.

As user1994 suggests, I have to dispatch a job before running this command, but I don't know how and where to dispatch it.

这是我的 LoginToWebsiteNotification 类:

class LoginToWebsiteNotification extends Notification implements ShouldQueue
{
    use Queueable;

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

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('u Loggedin')
            ->view('emails.login-to-website');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

这就是我从 LoginController 调用此通知的方式:

And this is how I called this notification from LoginController:

protected function authenticated(Request $request, $user)
{
    $user->notify(new LoginToWebsiteNotification());
    return $this->loggendin($request , $user);
}

所以,请您帮我一下,我将非常感谢!

So would you please help me out with this, I would really appreciate that!

预先感谢...

推荐答案

它没有冻结,只是在等待工作.因此,首先派遣一份工作,然后您将看到它正在工作:)

Its not frozen, its just waiting for a job. So firstly dispatch a job and then you will see it working :)

请查看有关 Laravel派遣工作的官方文档

这篇关于如何在运行队列之前分派作业:work命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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