management commands: Add sleep_forever to lib/management.

This commit is contained in:
Rishi Gupta 2018-08-15 12:02:56 -07:00 committed by Tim Abbott
parent d5f752df84
commit c3a912f8b6
4 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,7 @@
# Library code for use in management commands
import sys
import time
from argparse import ArgumentParser
from django.conf import settings
@ -29,6 +30,10 @@ def check_config() -> None:
raise CommandError("Error: You must set %s in /etc/zulip/settings.py." % (setting_name,))
def sleep_forever() -> None:
while True: # nocoverage
time.sleep(10**9)
class ZulipBaseCommand(BaseCommand):
def add_realm_args(self, parser: ArgumentParser, required: bool=False,
help: Optional[str]=None) -> None:

View File

@ -20,6 +20,7 @@ from ujson import loads
from zerver.lib.context_managers import lockfile
from zerver.lib.logging_util import log_to_file
from zerver.lib.management import sleep_forever
from zerver.lib.send_email import EmailNotDeliveredException, send_email
from zerver.models import ScheduledEmail
@ -39,7 +40,7 @@ Usage: ./manage.py deliver_email
def handle(self, *args: Any, **options: Any) -> None:
if settings.EMAIL_DELIVERER_DISABLED:
time.sleep(10**9) # "infinity seconds"
sleep_forever()
with lockfile("/tmp/zulip_email_deliver.lockfile"):
while True:

View File

@ -10,6 +10,7 @@ from django.utils.timezone import now as timezone_now
from zerver.lib.context_managers import lockfile
from zerver.lib.logging_util import log_to_file
from zerver.lib.management import sleep_forever
from zerver.models import ScheduledMessage, Message, get_user
from zerver.lib.actions import do_send_messages
from zerver.lib.addressee import Addressee
@ -55,8 +56,7 @@ Usage: ./manage.py deliver_scheduled_messages
# not sound right. Actually we do this check to avoid running this
# process on every server that might be in service to a realm. See
# the comment in zproject/settings.py file about renaming this setting.
while True:
time.sleep(10*9)
sleep_forever()
with lockfile("/tmp/zulip_scheduled_message_deliverer.lockfile"):
while True:

View File

@ -14,6 +14,7 @@ from django.conf import settings
from django.core.management.base import BaseCommand
from zerver.lib.context_managers import lockfile
from zerver.lib.management import sleep_forever
from zilencer.lib.stripe import StripeConnectionError, \
run_billing_processor_one_step
from zilencer.models import BillingProcessor
@ -28,7 +29,7 @@ Usage: ./manage.py process_billing_updates
def handle(self, *args: Any, **options: Any) -> None:
if not settings.BILLING_PROCESSOR_ENABLED:
time.sleep(10**9) # "infinity seconds"
sleep_forever()
with lockfile("/tmp/zulip_billing_processor.lockfile"):
while True: