简体   繁体   English

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 [
            //
        ];
    }
}

I am using laravel 5.5 email notification. 我正在使用laravel 5.5电子邮件通知。 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. 我正在使用supervisor来监视队列进程。

I have also cleared the view cache by running below command but it does work 我还通过运行以下命令清除了视图缓存,但它确实有效

php artisan view:clear

I have also restarted the queue 我也重新启动了队列

php artisan queue:restart

I have also ran 我也跑了

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. 由于worker已经加载了旧类,因此这些类发生的任何更改都不会生效。

You can read this at Laravel documentation: 您可以在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. 您可以通过发出queue:restart命令优雅地重新启动所有worker。

So, to have your notification content updated, you have to kill all queue workers running and restart them. 因此,要更新通知内容,必须终止所有正在运行的队列工作程序并重新启动它们。

This suggested solution (since you are using Supervisor) to restart Supervisor will work perfectly for you. 这个建议的解决方案(因为你使用Supervisor)重启Supervisor将完美地为你工作。

supervisorctl restart all

But, I do not recommend doing that as restarting Supervisor will hard-killing your queue workers and the current processed job will be lost! 但是,我不建议这样做,因为重新启动Supervisor会严重杀死您的队列工作人员并且当前处理的作业将丢失!

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

That is why the artisan command to restart queue is exists: 这就是为什么存在重启队列的artisan命令的原因:

php artisan queue:restart

You should be using this command to kill the queue workers and the Supervisor will get them started again for you. 您应该使用此命令来终止队列工作程序,并且Supervisor将为您重新启动它们。

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 . 这就是所谓的优雅杀戮

To get this artisan command work, be sure to setup a proper cache driver for Laravel as the restart signal is broadcasted via cache. 要使这个artisan命令工作,请确保为Laravel设置适当的缓存驱动程序,因为重新启动信号是通过缓存广播的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM