mirror of https://github.com/zulip/zulip.git
missedmessage_emails: Backoff the background worker retries.
This commit is contained in:
parent
7db916fe66
commit
b2ebe34500
|
@ -116,6 +116,7 @@ class MissedMessageWorker(QueueProcessingWorker):
|
||||||
super().start()
|
super().start()
|
||||||
|
|
||||||
def work(self) -> None:
|
def work(self) -> None:
|
||||||
|
backoff = 1
|
||||||
while True:
|
while True:
|
||||||
with sentry_sdk.start_transaction(
|
with sentry_sdk.start_transaction(
|
||||||
op="task",
|
op="task",
|
||||||
|
@ -128,12 +129,32 @@ class MissedMessageWorker(QueueProcessingWorker):
|
||||||
finished = self.background_loop()
|
finished = self.background_loop()
|
||||||
if finished:
|
if finished:
|
||||||
break
|
break
|
||||||
|
# Success running the background loop; reset our backoff
|
||||||
|
backoff = 1
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception(
|
logging.exception(
|
||||||
"Exception in MissedMessage background worker; restarting the loop",
|
"Exception in MissedMessage background worker; restarting the loop",
|
||||||
stack_info=True,
|
stack_info=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# We want to sleep, with backoff, before retrying
|
||||||
|
# the background loop; there may be
|
||||||
|
# non-recoverable errors which cause immediate
|
||||||
|
# exceptions, and we should avoid fast
|
||||||
|
# crash-looping. Instead of using time.sleep,
|
||||||
|
# which would block this thread and delay attempts
|
||||||
|
# to exit, we wait on the condition variable.
|
||||||
|
# With has_timeout set, this will only be notified
|
||||||
|
# by .stop(), below.
|
||||||
|
#
|
||||||
|
# Generally, delays in this background process are
|
||||||
|
# acceptable, so long as they at least
|
||||||
|
# occasionally retry.
|
||||||
|
with self.cv:
|
||||||
|
self.has_timeout = True
|
||||||
|
self.cv.wait(timeout=backoff)
|
||||||
|
backoff = min(30, backoff * 2)
|
||||||
|
|
||||||
def background_loop(self) -> bool:
|
def background_loop(self) -> bool:
|
||||||
with self.cv:
|
with self.cv:
|
||||||
if self.stopping:
|
if self.stopping:
|
||||||
|
|
Loading…
Reference in New Issue