zulip_updates: Prevent racing with self using a lock.

This commit is contained in:
Tim Abbott 2024-04-18 14:03:43 -07:00
parent 5c5e6b8cc5
commit 342a9bd5cd
2 changed files with 16 additions and 1 deletions

View File

@ -1,8 +1,11 @@
from argparse import ArgumentParser
from typing import Any
from django.conf import settings
from typing_extensions import override
from scripts.lib.zulip_tools import ENDC, WARNING
from zerver.lib.context_managers import lockfile_nonblocking
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.zulip_update_announcements import send_zulip_update_announcements
@ -20,4 +23,13 @@ class Command(ZulipBaseCommand):
@override
def handle(self, *args: Any, **options: Any) -> None:
send_zulip_update_announcements(skip_delay=options["skip_delay"])
with lockfile_nonblocking(
settings.ZULIP_UPDATE_ANNOUNCEMENTS_LOCK_FILE,
) as lock_acquired:
if lock_acquired:
send_zulip_update_announcements(skip_delay=options["skip_delay"])
else:
print(
f"{WARNING}Update announcements lock {settings.ZULIP_UPDATE_ANNOUNCEMENTS_LOCK_FILE} is unavailable;"
f" exiting.{ENDC}"
)

View File

@ -699,6 +699,9 @@ AUTH_LOG_PATH = zulip_path("/var/log/zulip/auth.log")
SCIM_LOG_PATH = zulip_path("/var/log/zulip/scim.log")
ZULIP_WORKER_TEST_FILE = zulip_path("/var/log/zulip/zulip-worker-test-file")
ZULIP_UPDATE_ANNOUNCEMENTS_LOCK_FILE = zulip_path(
"/home/zulip/deployments/zulip_update_announcements.lock"
)
if IS_WORKER: