mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
tornado: Add a retry with backoff to django-to-tornado requests.
This better hides errors from users during the moments when Tornado is being restarted.
This commit is contained in:
committed by
Tim Abbott
parent
e87aecf61c
commit
bb754e0902
@@ -5,6 +5,8 @@ from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Union
|
|||||||
import requests
|
import requests
|
||||||
import ujson
|
import ujson
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
from requests.packages.urllib3.util.retry import Retry
|
||||||
|
|
||||||
from zerver.lib.queue import queue_json_publish
|
from zerver.lib.queue import queue_json_publish
|
||||||
from zerver.models import Client, Realm, UserProfile
|
from zerver.models import Client, Realm, UserProfile
|
||||||
@@ -20,6 +22,15 @@ def requests_client() -> requests.Session:
|
|||||||
# Disable trusting the environment, so requests don't
|
# Disable trusting the environment, so requests don't
|
||||||
# go through any env-configured external proxy.
|
# go through any env-configured external proxy.
|
||||||
c.trust_env = False
|
c.trust_env = False
|
||||||
|
|
||||||
|
# During restarts, the tornado server may be down briefly
|
||||||
|
retry = Retry(
|
||||||
|
total=3,
|
||||||
|
backoff_factor=1,
|
||||||
|
)
|
||||||
|
adapter = HTTPAdapter(max_retries=retry)
|
||||||
|
for scheme in ("https://", "http://"):
|
||||||
|
c.mount(scheme, adapter)
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def request_event_queue(user_profile: UserProfile, user_client: Client, apply_markdown: bool,
|
def request_event_queue(user_profile: UserProfile, user_client: Client, apply_markdown: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user