Navigation Menu

Skip to content

Commit

Permalink
Add a retry when sending to Slack
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdabbad00 committed Dec 14, 2019
1 parent 6ed8083 commit c50e74e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions utils/toslack.py
Expand Up @@ -2,6 +2,7 @@
import requests
import sys
import os
import time

# Usage: Set the environment variable SLACK_WEBHOOK to https://hooks.slack.com/services/XXXX/YYYYY

Expand All @@ -18,6 +19,14 @@
webhook_url, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'}
)
if response.status_code == 429:
# Rate-limited. Sleep and retry
time.sleep(5)
response = requests.post(
webhook_url, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'}
)

if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
Expand Down

0 comments on commit c50e74e

Please sign in to comment.