laravel 5.5 电子邮件通知未更新内容

laravel 5.5 email notification not updating content

<?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 电子邮件通知。我已经更改了此邮件通知,但它已缓存在某个地方。我的应用程序向我发送包含旧内容的邮件,而不是我在此处共享的当前代码片段。我正在使用主管来监视队列进程。

我还通过下面的命令 运行 清除了视图缓存,但它确实有效

php artisan view:clear

我也重启了队列

php artisan queue:restart

我也有运行

php artisan config:cache

但似乎没有什么适合我。

这个问题可能与主管有关吗?

此问题与缓存完全无关。当您 运行 队列工作者时,所有通知 类 将被加载一次。

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

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

Running Worker Section:

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 Workers & Deployment Section:

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.

因此,要更新您的通知内容,您必须杀死所有队列工作人员 运行ning 并重新启动它们。

这个建议的重启 Supervisor 的解决方案(因为你正在使用 Supervisor)将非常适合你。

supervisorctl restart all

但是,我不建议这样做,因为重新启动 Supervisor 会硬杀你的队列工作人员和当前处理的作业将会丢失!

编辑: 使用 Supervisor 重启命令对于 Laravel 5.4+ 是安全的,但是,请确保设置“stopwaitsecs” (在您的工作人员的主管配置文件中)设置为高于估计的作业处理时间的值。

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

php artisan queue:restart

您应该使用此命令来终止队列工作人员,Supervisor 会为您重新启动它们。

但是,请记住,此命令需要一些时间才能生效,因为它会向所有队列工作人员广播重启信号 运行ning 并且队列工作人员只会在收到信号后捕获信号完成处理他们当前的工作。那就是所谓的graceful-killing.

要使此 artisan 命令正常工作,请务必为 Laravel 设置合适的缓存驱动程序,因为重启信号是通过缓存广播的。