laravel 5.5电子邮件通知不更新内容 [英] laravel 5.5 email notification not updating content

查看:56
本文介绍了laravel 5.5电子邮件通知不更新内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class VerifyEmailNotification extends Notification implements ShouldQueue
{
    use Queueable;

    protected $token;

    /**
    * Create a new notification instance.
    *
    * @return void
    */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
    * 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(config('constants.title') . ' - Please Verify Your Email')
            ->line('You are receiving this email because you have sign up on ' . config('constants.title') . '.')
            ->action('Verify Email', url(config('app.url').route('verify_email', ['token' => $this->token], false)))
            ->line('If you did not sign up on ' . config('constants.title') . ', no further action is required.');
    }

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

我正在使用laravel 5.5电子邮件通知.我已经更改了此邮件通知,但已将其缓存.我的应用程序向我发送的邮件包含旧内容,而不是我在此处共享的当前代码段.我正在使用主管来监视队列过程.

I am using laravel 5.5 email notification. I have changed this mail notification, but somewhere it has been cached. My Application is sending me mail with old content, not with the current code snippet that i have shared here. I am using supervisor to monitor queue processes.

我还通过运行以下命令清除了视图缓存,但它确实起作用

I have also cleared the view cache by running below command but it does work

php artisan view:clear

我还重新启动了队列

php artisan queue:restart

我也跑过

php artisan config:cache

但是对我来说似乎没有任何作用.

but nothing seems to work for me.

此问题可能与主管有关吗?

Is this issue can be related to supervisor?

推荐答案

此问题根本与缓存无关.当您运行队列工作器时,所有通知类将被加载一次.

This issue is not related to cache at all. When you run the queue worker all the notifications classes will be loaded once.

由于工作人员已经加载了旧的类,因此对这些类所做的任何更改都不会生效.

Any changes happen to these classes will not take effect as the worker already loaded the old classes.

您可以在Laravel文档中阅读以下内容:

You can read this at Laravel documentation:

正在运行的工人"部分:

请记住,队列工作器是长期存在的进程,并将已启动的应用程序状态存储在内存中.因此,启动它们后,他们将不会注意到代码库中的更改.因此,在部署过程中,请确保重新启动队列工作器.

Remember, queue workers are long-lived processes and store the booted application state in memory. As a result, they will not notice changes in your code base after they have been started. So, during your deployment process, be sure to restart your queue workers.

队列工人&部署部分:

由于队列工作器是长期存在的进程,因此如果不重新启动,它们将不会对您的代码进行更改.因此,使用队列工作程序部署应用程序的最简单方法是在部署过程中重新启动工作程序.您可以通过发出queue:restart命令来正常重启所有工作线程.

Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command.

因此,要更新通知内容,必须杀死所有正在运行的队列工作器并重新启动它们.

So, to have your notification content updated, you have to kill all queue workers running and restart them.

此建议的解决方案(因为您正在使用Supervisor)重新启动Supervisor将非常适合您.

This suggested solution (since you are using Supervisor) to restart Supervisor will work perfectly for you.

supervisorctl restart all

但是,我不建议您这样做,因为重新启动Supervisor会强行杀死您的队列工作人员,并且当前处理的工作将会丢失!

But, I do not recommend doing that as restarting Supervisor will hard-killing your queue workers and the current processed job will be lost!

对于Laravel 5.4+,使用Supervisor重新启动命令是安全的,但是请确保将" stopwaitsecs "(在工作程序的管理员配置文件中)设置为该值高于估计的作业处理时间.

Using Supervisor restart command is safe for Laravel 5.4+ but, make sure that to set "stopwaitsecs" (in your supervisor config file of the worker) to a value higher than the estimated job processing time.

这就是存在用于重启队列的artisan命令的原因:

That is why the artisan command to restart queue is exists:

php artisan queue:restart

您应该使用此命令来杀死队列工作者,并且Supervisor将为您重新启动它们.

You should be using this command to kill the queue workers and the Supervisor will get them started again for you.

但是,请记住,此命令生效之前需要花费一些时间,因为它将向所有正在运行的队列工作程序广播重新启动信号,并且队列工作程序仅在完成处理当前任务后才捕获该信号.这就是所谓的优雅杀戮.

But, keep in mind that this command will take some time until it takes effect as it will broadcast a restart signal to all the queue workers running and the queue workers will only capture the signal once it finishes processing their current job. That what is called graceful-killing.

要使此artisan命令正常工作,请确保为Laravel设置适当的缓存驱动程序,因为重新启动信号是通过缓存广播的.

这篇关于laravel 5.5电子邮件通知不更新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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