发送通知时,它会给出错误

When sending notifications, it gives an error

提问人:Андрей Двойкин 提问时间:10/4/2023 最后编辑:Андрей Двойкин 更新时间:10/5/2023 访问量:64

问:

通过队列向大量用户发送通知时,发送了一半用户后全部陷入错误

(GuzzleHttp\Exception\ConnectException:cURL 错误 6:无法解析 /var/www/jai/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210 中 https://fcm.googleapis.com/fcm/send 的主机:fcm.googleapis.com(请参阅 https://curl.haxx.se/libcurl/c/libcurl-errors.html)。

之后,它停止并且不再继续工作。告诉我如何处理此错误并继续进一步执行队列。

public function handle(): void
{
    try {
        $usersGroup = User::query()->whereNotNull('fcm_token')
            ->select(['id', 'fcm_token', 'gender']);

        if ($this->group === UserNotification::GROUP_MALE) {
            $usersGroup = $usersGroup->where('gender', '=', User::MALE);
        }


        if ($this->group === UserNotification::GROUP_FEMALE) {
            $usersGroup = $usersGroup->where('gender', User::FEMALE);
        }

        $usersGroup->chunk(1500, function ($users) {

            foreach ($users as $user) {
                Log::channel('notification')
                    ->debug("Sending push notification to {$this->group} user group:", [
                        'user_id' => $user->id,
                        'fcm_token' => $user->fcm_token
                    ]);
                $this->fcmService->send($user->fcm_token, $this->title, $this->body);
            }
        });
    }catch (ConnectException $e){
        Log::error('Ошибка ConnectException: ' . $e->getMessage());
    }

}
拉维尔

评论

0赞 SuperDJ 10/4/2023
请添加无效代码片段
1赞 aynber 10/4/2023
Could not resolve host: fcm.googleapis.com表示它无法再找到该主机。如果它发生在一个大型队列的中间,那么它可能是你自己的/服务器网络中的某些东西断开了连接或限制了它
0赞 Андрей Двойкин 10/5/2023
您能告诉我如何忽略此错误并继续执行队列吗?
1赞 aynber 10/5/2023
你真的不能忽视它,因为这意味着它不会发送。如果是循环,请使用 try/catch,并偶尔暂停(睡眠)。如果它不是循环,则可能需要对用户进行分块并循环。
1赞 aynber 10/5/2023
只在 Log::channel/send 周围放置一个 try/catch。我还建议在 foreach 之后睡一觉,只有几秒钟,让网络有一些喘息的空间。

答: 暂无答案