From 676a1ff730f4acf3696a0401302dc3792ec66e25 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Sep 15 2020 09:57:42 +0000 Subject: send_hook_payload: retry 10 times with tenacity before failing This change makes the service more resilient in case of network issues. --- diff --git a/fmgateway/callback.py b/fmgateway/callback.py index 9920373..944dc1e 100644 --- a/fmgateway/callback.py +++ b/fmgateway/callback.py @@ -16,6 +16,7 @@ import json import logging import requests +from tenacity import retry, stop_after_attempt, wait_exponential from fedora_messaging import config from twisted.web import server, resource from twisted.internet import endpoints, reactor @@ -55,6 +56,14 @@ stats = { errors = [] errors_size_limit = 100 +retry_request = retry( + # Raise the real exception instead of RetryError + reraise=True, + # Stop after 10 attempts + stop=stop_after_attempt(10), + # Slowly wait more + wait=wait_exponential(multiplier=1, min=1, max=10)) + FMMetricsCounter = Counter("fm_counter", "Counter (int) of messages", ["status"]) FMGauge = Gauge("fm_gauge", "Gauge (time) last event", ["status"]) @@ -86,6 +95,7 @@ def reduce_topic(topic): return base_topic +@retry_request def send_hook_payload(payload, url, project_fullname, verify_ssl=True): log.info( "Sending payload for topic: %s, project_fullname: %s -> %s" diff --git a/requirements.txt b/requirements.txt index 7984eeb..cb5460d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ requests fedora-messaging prometheus_client +tenacity