Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

management: Take a lock in crons that must not overlap.

Alex Vandiver3664c6a7b5f5
diff --git a/zerver/management/commands/fetch_tor_exit_nodes.py b/zerver/management/commands/fetch_tor_exit_nodes.py
index ac40a0f939f..9f25265a928 100644
--- a/zerver/management/commands/fetch_tor_exit_nodes.py
+++ b/zerver/management/commands/fetch_tor_exit_nodes.py
@@ -7,7 +7,7 @@ from django.conf import settings
from typing_extensions import override
from urllib3.util import Retry
-from zerver.lib.management import ZulipBaseCommand, abort_cron_during_deploy
+from zerver.lib.management import ZulipBaseCommand, abort_cron_during_deploy, abort_unless_locked
from zerver.lib.outgoing_http import OutgoingSession
@@ -45,6 +45,7 @@ Does nothing unless RATE_LIMIT_TOR_TOGETHER is enabled.
@override
@abort_cron_during_deploy
+ @abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
if not settings.RATE_LIMIT_TOR_TOGETHER:
return
diff --git a/zerver/management/commands/update_channel_recently_active_status.py b/zerver/management/commands/update_channel_recently_active_status.py
index 089748d1ff1..ab1b49f7973 100644
--- a/zerver/management/commands/update_channel_recently_active_status.py
+++ b/zerver/management/commands/update_channel_recently_active_status.py
@@ -5,7 +5,7 @@ from django.conf import settings
from typing_extensions import override
from zerver.lib.logging_util import log_to_file
-from zerver.lib.management import ZulipBaseCommand
+from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
from zerver.lib.streams import check_update_all_streams_active_status
## Logging setup ##
@@ -17,6 +17,7 @@ class Command(ZulipBaseCommand):
help = """Update the `Stream.is_recently_active` field to False for channels whose message history has aged to the point where it is no longer recently active."""
@override
+ @abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
count = check_update_all_streams_active_status()
logger.info("Marked %s channels as not recently active.", count)
diff --git a/zerver/management/commands/update_subscriber_counts.py b/zerver/management/commands/update_subscriber_counts.py
index 6df8e5b05c8..181b3210302 100644
--- a/zerver/management/commands/update_subscriber_counts.py
+++ b/zerver/management/commands/update_subscriber_counts.py
@@ -10,7 +10,7 @@ from django.utils.timezone import now as timezone_now
from typing_extensions import override
from zerver.lib.logging_util import log_to_file
-from zerver.lib.management import ZulipBaseCommand
+from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
from zerver.models import RealmAuditLog, Stream, Subscription
from zerver.models.realm_audit_logs import AuditLogEventType
@@ -36,6 +36,7 @@ accurate; this command is run as a daily cron job to ensure the number is accura
self.add_realm_args(parser, help="The optional name of the realm to limit to")
@override
+ @abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
realm = self.get_realm(options)
streams = Stream.objects.all()