Skip to content

Commit

Permalink
bug(webhooks): add configurable request timeout for webhooks (#2419)
Browse files Browse the repository at this point in the history
- Handle unhandled connection error while sending webhooks
  • Loading branch information
DavisRayM committed May 11, 2023
1 parent 8a4dc04 commit 3e3e662
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion onadata/apps/restservice/services/generic_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
"""
import json

from django.conf import settings

import requests
from requests.exceptions import ConnectionError as RequestsConnectionError

from onadata.apps.restservice.RestServiceInterface import RestServiceInterface

WEBHOOK_TIMEOUT = getattr(settings, "WEBHOOK_TIMEOUT", 30)


class ServiceDefinition(RestServiceInterface):
"""Post submisison JSON data to an external service that accepts a JSON post."""
Expand All @@ -21,4 +26,9 @@ def send(self, url, data=None):
if data:
post_data = json.dumps(data.json)
headers = {"Content-Type": "application/json"}
requests.post(url, headers=headers, data=post_data)
try:
requests.post(
url, headers=headers, data=post_data, timeout=WEBHOOK_TIMEOUT
)
except RequestsConnectionError:
pass

0 comments on commit 3e3e662

Please sign in to comment.