亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Redis 限制 Laravel 作業“嘗試次數過多或運行時間過長”

Redis 限制 Laravel 作業“嘗試次數過多或運行時間過長”

PHP
MMTTMM 2023-09-08 21:29:56
我想使用 Laravel Queue 和 Redis 來通過 nexmo 發送短信,但有些作業失敗了,我不明白為什么。在我的本地環境中,我每 10 秒發送 1 條短信,所以這是我工作的處理方法:public function handle()    {         Redis::throttle('throttle:sms')->allow(1)->every(10)->then(function(){            Log::info($this->notifId." start : ".date('H:m:s'));            try{                $before = microtime(true);                $response = Nexmo::message()->send([                                'to'   => $this->to,                                'from' => '16105552344',                                'text' => $this->message                            ]);                $notif = NotificationHistory::find($this->notifId);                $notif->nexmo_message_id=$response->getMessageId();                $notif->save();                $after = microtime(true);                Log::info(($after-$before)." sec\n");            }catch(Exeption $e){                log::warning($e);            }        },function($error){            Log::error($error);            return $this->release(10);//release job in X second        });    }但當我達到嘗試限制時,我Illuminate\Contracts\Redis\LimiterTimeoutException終于得到了一些。MaxAttemptsExceededException我開始我的工作人員php artisan queue:work --queue=sms --timeout=60 并像這樣調度我的工作:foreach($someEntities as $entitiy) {            $notif = new NotificationHistory();            $notif->notifiable()->associate($entity);            $notif->message=$entity->message;            $notif->status=NotificationHistory::$statusList[-1];            $notif->save();            dispatch(new SendSMS($entity->message."_".$notif->id,$entity->phone,$notif->id))->onConnection('redis')->onQueue('sms');    }當嘗試發送 8 條短信時,前 5 條或 6 條有效,但其他短信例外。編輯 我在沒有 nexmo 的情況下得到同樣的錯誤:public function handle()    {         Redis::throttle('throttle:sms')->allow(1)->every(10)->then(function(){            Log::info($this->notifId." startAt : ".date('H:m:s'));        },function($error){            Log::error($error);            return $this->release(10);//release job in X second        });    }
查看完整描述

1 回答

?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

問題是“horizon”文件強制嘗試次數為 3。

事實上,隊列工作器并不只每 10 秒運行一次,如果隊列中有東西,它會連續運行。當它處理一個作業時,如果它在過去 10 秒內已經處理過一個作業,它將從隊列中刪除當前作業并在 X 秒內將其放回(在 中定義),生成并增加它的 attemptsrelease(x)LimiterTimeoutException。因此,當工人對同一個工作進行 3 次嘗試時,就會失敗。


查看完整回答
反對 回復 2023-09-08
  • 1 回答
  • 0 關注
  • 110 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號