我想使用 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
});
}
Qyouu