我想使用 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 次嘗試時,就會失敗。
- 1 回答
- 0 關注
- 110 瀏覽
添加回答
舉報
0/150
提交
取消