美文网首页
laravel-队列配置

laravel-队列配置

作者: lemon_jun | 来源:发表于2020-11-24 17:17 被阅读0次

php artisan make:job 文件名称 创建队列
php artisan queue:work --daemon 启动且监听
php artisan queue:work --queue={GeneratePdfReport} 消耗一次队列
php artisan queue:restart 重启队列
生成文件修改:

class GeneratePdfReport implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * 任务运行的超时时间。
     *
     * 置时间必须小于默认时间 ,默认 90秒
     * @var int
     */
    public $timeout = 70;

    /**
     * 任务最大尝试次数。
     *
     * @var int
     */
    public $tries = 5;

    /***
     * 报告ID
     * @var
     */
    protected $report_id;

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

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //调用消费的方法
        xxxxxx::xxx($id);
    }
}

调用方法:

//插入队列,延迟1分钟执行
dispatch(new GeneratePdfReport($id))->delay(Carbon::now()->addMinutes(1));

supervisor 进程管理 安装按照laravel文档即可
1、cd /etc/supervisor 进入服务监控配置文件目录
2、vim supervisord.conf 添加下面代码块

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

3、cd ./conf.d 进入配置目录 vim dingxiang-pdf-worker.conf 添加下面代码(需要看下,command与stdout_logfile目录更换为自己的)

[program:dingxiang-pdf-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/php 项目路径/artisan queue:work redis --sleep=3 --daemon
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=项目路径/storage/logs/worker.log

4、sudo killall supervisord 关闭所有进程
5、supervisord -c /etc/supervisor/supervisord.conf 重新启动并载入新的配置
6、supervisorctl status 查看管理进程状态(所有配置文件名称存在即可)
https://blog.51cto.com/sf1314/2128372?utm_source=oschina-app 错误举例

相关文章

  • laravel-队列配置

    php artisan make:job 文件名称 创建队列php artisan queue:work --da...

  • laravel-队列

    此处用laravel5.8做示例 .env配置 # .env 中 配置连接方式。对一般中小型应用推荐使用 Redi...

  • RabbitMQ实现消息的最终一致性

    通过rabbit死信队列实现消息的最终一致性 配置消费队列 配置死信队列 被拒绝的消息会进入死信队列 正常数据消费...

  • rabbitmq动态创建exchange与队列

    rabbitmq配置 创建队列

  • config/queue.php

    队列配置文件源码

  • Laravel-目录结构

    Laravel-目录结构[https://www.cnblogs.com/superzwb/p/11855803....

  • vhost-net 3 -- 网卡多队列

    虚拟机配置接口多队列 为虚拟机接口配置多队列可以提高虚拟机网卡的收发性能。如下,我们为vm的一个网卡配置了4队列。...

  • SpringBoot集成RabbitMQ开发

    一、基础配置开发 1.1 pom依赖 1.2 ymal配置 1.3 简单队列 模拟最简单的队列,和交换机不做任何的...

  • spring集成rabbitmq

    maven配置 rabbitMQ配置文件 Spring配置 申明一个消息队列Queue tipsdurable:是...

  • filebeat

    filebeat 架构图 配置文件 配置服务 logstash配置 增加缓冲队列 安装redis filebeat...

网友评论

      本文标题:laravel-队列配置

      本文链接:https://www.haomeiwen.com/subject/dgxwiktx.html