Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable timeouts for webhook requests #2419

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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