forked from Aniketc068/MX-Signer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook_utils.py
More file actions
38 lines (30 loc) · 1.45 KB
/
webhook_utils.py
File metadata and controls
38 lines (30 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
import json
import time
def send_webhook_with_retry(webhook_url, webhook_payload, retries=3, delay=5):
headers = {'Content-Type': 'application/json'}
# Log the payload and retry information
#print(f"Attempting to send to webhook URL: {webhook_url}")
#print(f"Payload: {json.dumps(webhook_payload, indent=4)}")
for attempt in range(retries):
try:
# Sending the POST request to the Webhook URL
webhook_response = requests.post(webhook_url, json=webhook_payload, headers=headers, timeout=30)
# Log the status code and response content
# print(f"Attempt {attempt + 1}: Webhook response status: {webhook_response.status_code}")
# print(f"Webhook response content: {webhook_response.text}")
if webhook_response.status_code == 200:
# print(f"Webhook sent successfully to {webhook_url}")
return True
else:
# print(f"Failed to send webhook, status code: {webhook_response.status_code}")
# print(f"Response: {webhook_response.text}")
return False
except requests.exceptions.RequestException as e:
# print(f"Attempt {attempt + 1}: Failed to send webhook: {str(e)}")
pass
# Retry with a delay
time.sleep(delay)
# If all attempts fail, log and return False
# print("All attempts failed, returning failure.")
return False