Skip to content

Commit 192f792

Browse files
authored
add example for readme & retries
1 parent 5ad071d commit 192f792

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,26 @@ import requests
364364

365365

366366
class DeliverHook(Task):
367+
max_retries = 5
368+
367369
def run(self, target, payload, instance_id=None, hook_id=None, **kwargs):
368370
"""
369371
target: the url to receive the payload.
370372
payload: a python primitive data structure
371373
instance_id: a possibly None "trigger" instance ID
372374
hook_id: the ID of defining Hook object
373375
"""
374-
requests.post(
375-
url=target,
376-
data=json.dumps(payload),
377-
headers={'Content-Type': 'application/json'}
378-
)
376+
try:
377+
response = requests.post(
378+
url=target,
379+
data=json.dumps(payload),
380+
headers={'Content-Type': 'application/json'}
381+
)
382+
if response.status_code >= 500:
383+
response.raise_for_response()
384+
except requests.ConnectionError:
385+
delay_in_seconds = 2 ** self.request.retries
386+
self.retry(countdown=delay_in_seconds)
379387

380388

381389
def deliver_hook_wrapper(target, payload, instance, hook):

0 commit comments

Comments
 (0)