management: Add lockfiles to all _once management jobs.

These would be bad if more than once ran at once.
This commit is contained in:
Alex Vandiver 2024-04-23 19:30:37 +00:00 committed by Tim Abbott
parent 11dd6791c4
commit e8e6abdbba
8 changed files with 16 additions and 5 deletions

View File

@ -3,11 +3,13 @@ from typing import Any
from django.core.management.base import BaseCommand
from typing_extensions import override
from zerver.lib.management import abort_unless_locked
from zerver.lib.retention import archive_messages, clean_archived_data
class Command(BaseCommand):
@override
@abort_unless_locked
def handle(self, *args: Any, **options: str) -> None:
clean_archived_data()
archive_messages()

View File

@ -8,6 +8,7 @@ from typing_extensions import override
from zerver.actions.uploads import do_delete_old_unclaimed_attachments
from zerver.lib.attachments import get_old_unclaimed_attachments
from zerver.lib.management import abort_unless_locked
from zerver.lib.upload import all_message_attachments, delete_message_attachments
from zerver.models import ArchivedAttachment, Attachment
@ -44,6 +45,7 @@ class Command(BaseCommand):
)
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
delta_weeks = options["delta_weeks"]
print(f"Deleting unclaimed attached files older than {delta_weeks} weeks")

View File

@ -9,6 +9,7 @@ from typing_extensions import override
from zerver.lib.digest import DIGEST_CUTOFF, enqueue_emails
from zerver.lib.logging_util import log_to_file
from zerver.lib.management import abort_unless_locked
## Logging setup ##
logger = logging.getLogger(__name__)
@ -21,6 +22,7 @@ in a while.
"""
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
cutoff = timezone_now() - timedelta(days=DIGEST_CUTOFF)
enqueue_emails(cutoff)

View File

@ -3,12 +3,13 @@ from typing import Any
from typing_extensions import override
from zerver.actions.user_groups import promote_new_full_members
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
class Command(ZulipBaseCommand):
help = """Add users to full members system group."""
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
promote_new_full_members()

View File

@ -6,7 +6,7 @@ from django.conf import settings
from django.core.management.base import CommandError
from typing_extensions import override
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
from zerver.lib.soft_deactivation import (
do_auto_soft_deactivate_users,
do_soft_activate_users,
@ -57,6 +57,7 @@ class Command(ZulipBaseCommand):
)
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
if settings.STAGING:
print("This is a Staging server. Suppressing management command.")

View File

@ -3,7 +3,7 @@ from typing import Any, Iterable
from django.core.management.base import CommandParser
from typing_extensions import override
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
from zerver.lib.message import maybe_update_first_visible_message_id
from zerver.models import Realm
@ -23,6 +23,7 @@ class Command(ZulipBaseCommand):
)
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
target_realm = self.get_realm(options)

View File

@ -3,12 +3,13 @@ from typing import Any
from typing_extensions import override
from corporate.lib.stripe import downgrade_small_realms_behind_on_payments_as_needed
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
class Command(ZulipBaseCommand):
help = "Downgrade small realms that are running behind on payments"
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
downgrade_small_realms_behind_on_payments_as_needed()

View File

@ -3,7 +3,7 @@ from typing import Any
from django.conf import settings
from typing_extensions import override
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.management import ZulipBaseCommand, abort_unless_locked
if settings.BILLING_ENABLED:
from corporate.lib.stripe import invoice_plans_as_needed
@ -13,6 +13,7 @@ class Command(ZulipBaseCommand):
help = """Generates invoices for customers if needed."""
@override
@abort_unless_locked
def handle(self, *args: Any, **options: Any) -> None:
if settings.BILLING_ENABLED:
# Uncomment to test with a specific date.