duanliang1019 2019-03-01 01:02
浏览 374
已采纳

Laravel队列速率限制不执行工作

I'm attempting to implement Laravel 5.7's queue job rate limiting which for use when queue jobs hit an external API that's rate limited.

Here's my job:

    public function handle() {
        echo 'about to check throttling'.PHP_EOL;
        Redis::throttle('throttle-test')->allow(10)->every(5)->then(function () {
            // this is never executed
            echo 'doing work'.PHP_EOL;
        }, function () {
            // also never executed
            echo 'released back onto queue'.PHP_EOL;
            return $this->release(10);
        });
    }

There's no mention of needing to use Redis for queues, cache or anything of that nature in the docs, aside from "...application can interact with a Redis server." Either way, here's my env vars:

DB_CONNECTION=mysql
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=redis

I've confirmed the RedisServiceProvider is receiving the correct configuration it expects:

array:3 [
  "client" => "predis"
  "default" => array:4 [
    "host" => "redis"
    "password" => null
    "port" => "6379"
    "database" => 0
  ]
  "horizon" => array:5 [
    "host" => "redis"
    "password" => null
    "port" => "6379"
    "database" => 0
    "options" => array:1 [
      "prefix" => "horizon:"
    ]
  ]
]

I'm struggling to understand why there's no runtime errors, it's just that nothings get executed. If I comment out the throttle stuff the job runs fine and does what it's supposed to do. What am I missing about the requirements to use this throttling?

  • 写回答

2条回答 默认 最新

  • doudou521125 2019-03-12 01:26
    关注

    The documentation for Laravel in this case is very misleading. While it implies you only need a connection to Redis you actually have to be using Redis for your queues.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站