push_notifications: Set more reasonable timeouts.

This commit is contained in:
Tim Abbott
2023-12-07 12:23:54 -08:00
parent 19ac558d5f
commit d29d132e8a

View File

@@ -20,8 +20,8 @@ from zerver.models import OrgTypeEnum, Realm, RealmAuditLog
class PushBouncerSession(OutgoingSession):
def __init__(self) -> None:
super().__init__(role="push_bouncer", timeout=30)
def __init__(self, timeout: int = 15) -> None:
super().__init__(role="push_bouncer", timeout=timeout)
class PushNotificationBouncerError(Exception):
@@ -98,9 +98,23 @@ def send_to_push_bouncer(
headers = {"User-agent": f"ZulipServer/{ZULIP_VERSION}"}
headers.update(extra_headers)
if endpoint == "server/analytics":
# Uploading audit log and/or analytics data can require the
# bouncer to do a significant chunk of work in a few
# situations; since this occurs in background jobs, set a long
# timeout.
session = PushBouncerSession(timeout=90)
else:
session = PushBouncerSession()
try:
res = PushBouncerSession().request(
method, url, data=post_data, auth=api_auth, verify=True, headers=headers
res = session.request(
method,
url,
data=post_data,
auth=api_auth,
verify=True,
headers=headers,
)
except (
requests.exceptions.Timeout,