美文网首页
laravel 队列

laravel 队列

作者: 会飞一下 | 来源:发表于2021-05-07 17:37 被阅读0次

    //添加队列

    SyncJobs::dispatch(new JobService(),'funcName',array $class_args = [],array $func_args = [])->delay(now())->onQueue('queueName');
    ||
    $job = new SyncJobs(new JobService(),'funcName',array $class_args = [], array $func_args = [] );
    dispatch($job)->delay(now()->addMinutes(1))->onQueue('queueName');
    
    
    

    消费队列

    php artisan queue:work --queue=queueName
    
    #处理失败队列
    php artisan queue:failed  #查看失败任务
    php artisan queue:retry 5 #重试id为5的任务
    php artisan queue:retry all #重试所有任务
    php artisan queue:forget 5 #删除id为5的任务
    php artisan queue:flush #删除所有失败任务
    
    

    //通过supervisor管理

    通过supervisor管理

    安装 sudo apt-get install supervisor

    配置:通常在 /etc/supervisor/conf.d/

    [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
    autostart=true
    autorestart=true
    user=forge
    numprocs=8
    redirect_stderr=true
    stdout_logfile=/home/forge/app.com/worker.log
    stopwaitsecs=3600
    
    

    启动

    sudo supervisorctl reread
    
    sudo supervisorctl update
    
    sudo supervisorctl start laravel-worker:*
    sudo supervisorctl restart laravel-worker:*  #重启
    sudo supervisorctl stoplaravel-worker:*  #停止
    

    通过 horizon 监控队列

    horizon 安装

    composer require laravel/horizon

    horizon 配置

    php artisan horizon:install

    horizon 启动

    php artisan horizon

    horizon 访问

    http://localhsot/horizon
    通过horizon方便查看总的队列数量,消费情况,失败队列,成功队列等

    队列类 JobService 修改后,需要重启队列消费,否则不生效

    相关文章

      网友评论

          本文标题:laravel 队列

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