Skip to content

Commit 8cbf56d

Browse files
committed
feat(providers): added retry mechanism to google chat provider to overcome rate limiting
1 parent 5aea39e commit 8cbf56d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

keep/providers/google_chat_provider/google_chat_provider.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import http
12
import os
3+
import time
4+
25
import pydantic
36
import dataclasses
47
import requests
@@ -65,13 +68,23 @@ def _notify(self, message="", **kwargs: dict):
6568
if not message:
6669
raise ProviderException("Message is required")
6770

71+
def __send_message(url, body, headers, retries=3):
72+
for _ in range(retries):
73+
try:
74+
resp = requests.post(url, json=body, headers=headers)
75+
if resp.status_code == http.HTTPStatus.OK:
76+
return resp
77+
except requests.exceptions.RequestException as e:
78+
self.logger.error(f"Failed to send message to Google Chat: {e}")
79+
time.sleep(1)
80+
6881
payload = {
6982
"text": message,
7083
}
7184

72-
requestHeaders = {"Content-Type": "application/json; charset=UTF-8"}
85+
request_headers = {"Content-Type": "application/json; charset=UTF-8"}
7386

74-
response = requests.post(webhook_url, json=payload, headers=requestHeaders)
87+
response = __send_message(webhook_url, body=payload, headers=request_headers)
7588

7689
if not response.ok:
7790
raise ProviderException(

0 commit comments

Comments
 (0)