mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-25 21:47:00 +08:00
fixup! refactor webhooks request & add 2s delay
This commit is contained in:
parent
57db8f3a66
commit
c08665c640
1 changed files with 5 additions and 5 deletions
|
|
@ -29,7 +29,7 @@ class Webhooks:
|
||||||
self.notifiarr = notifiarr
|
self.notifiarr = notifiarr
|
||||||
self.apprise = apprise
|
self.apprise = apprise
|
||||||
|
|
||||||
def request_and_check(self, webhook_type, json):
|
def request_and_check(self, webhook, json):
|
||||||
"""
|
"""
|
||||||
Send a webhook request and check for errors.
|
Send a webhook request and check for errors.
|
||||||
retry up to 6 times if the response is a 500+ error.
|
retry up to 6 times if the response is a 500+ error.
|
||||||
|
|
@ -38,10 +38,10 @@ class Webhooks:
|
||||||
retry_attempts = 6
|
retry_attempts = 6
|
||||||
request_delay = 2
|
request_delay = 2
|
||||||
for retry_count in range(retry_attempts):
|
for retry_count in range(retry_attempts):
|
||||||
if webhook_type == "notifiarr":
|
if webhook == "notifiarr":
|
||||||
response = self.notifiarr.notification(json=json)
|
response = self.notifiarr.notification(json=json)
|
||||||
else:
|
else:
|
||||||
if webhook_type == "apprise":
|
if webhook == "apprise":
|
||||||
json["urls"] = self.apprise.notify_url
|
json["urls"] = self.apprise.notify_url
|
||||||
webhook_type = f"{self.apprise.api_url}/notify"
|
webhook_type = f"{self.apprise.api_url}/notify"
|
||||||
response = self.config.post(webhook_type, json=json)
|
response = self.config.post(webhook_type, json=json)
|
||||||
|
|
@ -49,7 +49,7 @@ class Webhooks:
|
||||||
return response
|
return response
|
||||||
time.sleep(request_delay)
|
time.sleep(request_delay)
|
||||||
retry_count += 1
|
retry_count += 1
|
||||||
raise Failed(f"({response.status_code} [{response.reason}]) after {retry_attempts} attempts.")
|
logger.warning(f"({response.status_code} [{response.reason}]) after {retry_attempts} attempts.")
|
||||||
|
|
||||||
def _request(self, webhooks, json):
|
def _request(self, webhooks, json):
|
||||||
"""Send a webhook request."""
|
"""Send a webhook request."""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue