加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – laravel 5.5电子邮件通知不更新内容

发布时间:2020-12-14 19:40:54 所属栏目:大数据 来源:网络整理
导读:?phpnamespace AppNotifications;use IlluminateBusQueueable;use IlluminateNotificationsNotification;use IlluminateContractsQueueShouldQueue;use IlluminateNotificationsMessagesMailMessage;class VerifyEmailNotification extends Notif
<?php

namespace AppNotifications;

use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;

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

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

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.

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

这个建议的解决方案(因为你使用Supervisor)重启Supervisor将完美地为你工作.

supervisorctl restart all

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

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

这就是为什么存在重启队列的artisan命令的原因:

php artisan queue:restart

您应该使用此命令来终止队列工作程序,并且Supervisor将为您重新启动它们.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读