php - laravel 5.5 邮件通知不更新内容

标签 php laravel queue supervisord email-notifications

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

我还通过运行以下命令清除了 View 缓存,但它确实有效

php artisan view:clear

我也重启了队列

php artisan queue:restart

我也跑过

php artisan config:cache

但似乎没有什么适合我。

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

最佳答案

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

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

您可以在 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.

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

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

supervisorctl restart all

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

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

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

php artisan queue:restart

你应该使用这个命令来杀死队列工作人员,主管会为你让他们重新启动。

但是请记住,此命令需要一些时间才能生效,因为它会向所有正在运行的队列工作程序广播重启信号,而队列工作程序只会在完成处理当前作业后捕获该信号。这就是所谓的优雅杀戮

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

关于php - laravel 5.5 邮件通知不更新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51895025/

相关文章:

php - 了解 wordpress 中的 crons 和一段代码

php - Laravel 使用多少成本/回合进行哈希处理?

php - 带闭包的 laravel 查询

asynchronous - Dart 中的 future 队列

java - 如何使用队列组织多线程工作?

php - 使用 PHP 的 SSL 客户端身份验证

php - 如何在 PHP 中的数字之间插入连字符?

php - 正则表达式从 URL 中提取文件扩展名

php - 删除数组中的重复项以及按相反顺序 PHP Laravel

tomcat - 从 Tomcat 连接到 Hornetq 时出错