【问题标题】:How do I enable queue:work from live server?如何启用队列:从实时服务器工作?
【发布时间】:2020-06-09 17:53:38
【问题描述】:

这个在我的本地服务器上运行良好,因为我可以运行命令。

php artisan queue:work

但是如何在实时服务器上实现呢? 我真的被这个问题困住了。但是因为我想通过邮件发送通知。所以,我正在关注使用 laravel 默认队列功能,因为它不会延迟并自动完成它的工作。所以,如果你能帮忙的话,真的很感激。

提前谢谢..

//我的.env配置

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

my jobs table from database

//我的新奖学金课程

namespace App\Notifications;

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

class NewScholarship extends Notification implements ShouldQueue
{
  use Queueable;



public $scholarship;


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

/**
 * 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)
                ->greeting('Hello, Subscriber!')
                ->subject('New Scholarship has been published')
                ->line('New Scholarship info has been published to our website')
                ->line('Titled as: '.$this->scholarship->title)
                ->line('To have a look click the button below')
                ->action('View details', url('s/details',$this->scholarship->slug))
                ->line('Thank you for your subscription!');
}

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

【问题讨论】:

    标签: laravel queue live


    【解决方案1】:

    生产的想法与开发的想法相同,您应该运行 queue:work 但是当然您不能不时地通过 ssh 连接到您的服务器并检查命令是否仍在运行,这就是为什么您应该使用类似 @ Laravel 推荐的 987654321@。

    这是quick introduction to supervisor in the Laravel documentation 基本上,如果您的服务器是 debian,您应该通过运行以下命令来安装主管包:

    sudo apt-get install supervisor SSH 到服务器后

    安装完成后,使用vi vim或nano访问/etc/supervisor/conf.d,创建配置文件ex:laravel-worker.conf

    下面是一个示例配置

    [program:laravel-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3 #"home/forge/app.com/artisan" is the path to your project root
    autostart=true
    autorestart=true
    user=forge
    numprocs=8
    redirect_stderr=true
    stdout_logfile=/home/forge/app.com/worker.log
    stopwaitsecs=3600
    

    来自 laravel 文档的注释:

    • 您应该确保 stopwaitsecs 的值大于运行时间最长的作业所消耗的秒数。否则,Supervisor 可能会在作业完成处理之前将其终止。
    • 在本例中,numprocs 指令将指示 Supervisor 运行 8 个 queue:work 进程并监控所有这些进程,如果它们失败则自动重新启动它们。
    • 您应该更改命令指令的 queue:work sqs 部分以反映您所需的队列连接。

    请注意,此信息来自上面链接的 laravel 文档

    如果您的服务器不是 debian,请查看official documentation of suppervisor

    创建配置文件后,您可以使用以下命令更新 Supervisor 配置并启动进程:

    sudo supervisorctl reread

    sudo supervisorctl update

    sudo supervisorctl start laravel-worker:*

    【讨论】:

    • 对不起,我没有找到任何终端来运行命令。有没有办法从本地服务器运行命令?我是 Windows 用户。
    • 你可以访问实时服务器吗?
    • 好的,如果实时服务器是 linux 服务器,请按照我的回答进行操作
    • 我的服务器操作系统是linux。从哪里可以运行这个命令?
    • 你如何访问你的服务器?如果通过 ssh,那么您在终端中。首先安装管理程序,然后添加配置文件。然后启动 suppervisor(我将编辑关于如何启动 suppervisor 的答案)
    【解决方案2】:

    你应该找一个叫做主管的东西

    查看示例

    tutorial

    【讨论】:

      猜你喜欢
      • 2022-11-07
      • 1970-01-01
      • 2021-02-07
      • 2013-09-27
      • 2017-03-12
      • 1970-01-01
      • 2013-10-01
      • 2019-01-03
      • 1970-01-01
      相关资源
      最近更新 更多