Skip to content

Commit

Permalink
feat(providers): added retry mechanism to google chat provider to ove…
Browse files Browse the repository at this point in the history
…rcome rate limiting
  • Loading branch information
pehlicd committed Nov 21, 2024
1 parent 5aea39e commit 8cbf56d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions keep/providers/google_chat_provider/google_chat_provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import http
import os
import time

import pydantic
import dataclasses
import requests
Expand Down Expand Up @@ -65,13 +68,23 @@ def _notify(self, message="", **kwargs: dict):
if not message:
raise ProviderException("Message is required")

def __send_message(url, body, headers, retries=3):
for _ in range(retries):
try:
resp = requests.post(url, json=body, headers=headers)
if resp.status_code == http.HTTPStatus.OK:
return resp
except requests.exceptions.RequestException as e:
self.logger.error(f"Failed to send message to Google Chat: {e}")
time.sleep(1)

payload = {
"text": message,
}

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

response = requests.post(webhook_url, json=payload, headers=requestHeaders)
response = __send_message(webhook_url, body=payload, headers=request_headers)

if not response.ok:
raise ProviderException(
Expand Down

0 comments on commit 8cbf56d

Please sign in to comment.