deliver_email, deliver_scheduled_messages: Remove lock file.

Tim believes it’s useless.

https://github.com/zulip/zulip/pull/11285#discussion_r248110926

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2019-01-14 18:02:43 -08:00 committed by Tim Abbott
parent 0a8598ce65
commit c0792808e2
2 changed files with 33 additions and 35 deletions

View File

@ -9,6 +9,7 @@ condition. (Alternatively, you can set `EMAIL_DELIVERER_DISABLED=True`
on all but one machine to make the command have no effect.)
"""
import os
import logging
import time
from typing import Any
@ -18,7 +19,6 @@ from django.core.management.base import BaseCommand
from django.utils.timezone import now as timezone_now
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, \
@ -43,21 +43,20 @@ Usage: ./manage.py deliver_email
if settings.EMAIL_DELIVERER_DISABLED:
sleep_forever()
with lockfile("/tmp/zulip_email_deliver.lockfile"):
while True:
email_jobs_to_deliver = ScheduledEmail.objects.filter(
scheduled_timestamp__lte=timezone_now())
if email_jobs_to_deliver:
for job in email_jobs_to_deliver:
data = loads(job.data)
handle_send_email_format_changes(data)
try:
send_email(**data)
job.delete()
except EmailNotDeliveredException:
logger.warning("%r not delivered" % (job,))
time.sleep(10)
else:
# Less load on the db during times of activity,
# and more responsiveness when the load is low
time.sleep(2)
while True:
email_jobs_to_deliver = ScheduledEmail.objects.filter(
scheduled_timestamp__lte=timezone_now())
if email_jobs_to_deliver:
for job in email_jobs_to_deliver:
data = loads(job.data)
handle_send_email_format_changes(data)
try:
send_email(**data)
job.delete()
except EmailNotDeliveredException:
logger.warning("%r not delivered" % (job,))
time.sleep(10)
else:
# Less load on the db during times of activity,
# and more responsiveness when the load is low
time.sleep(2)

View File

@ -1,4 +1,5 @@
import logging
import os
import time
from typing import Any, Dict
from datetime import timedelta
@ -8,7 +9,6 @@ from django.core.management.base import BaseCommand
from django.db import transaction
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_by_delivery_email
@ -58,19 +58,18 @@ Usage: ./manage.py deliver_scheduled_messages
# the comment in zproject/settings.py file about renaming this setting.
sleep_forever()
with lockfile("/tmp/zulip_scheduled_message_deliverer.lockfile"):
while True:
messages_to_deliver = ScheduledMessage.objects.filter(
scheduled_timestamp__lte=timezone_now(),
delivered=False)
if messages_to_deliver:
for message in messages_to_deliver:
with transaction.atomic():
do_send_messages([self.construct_message(message)])
message.delivered = True
message.save(update_fields=['delivered'])
while True:
messages_to_deliver = ScheduledMessage.objects.filter(
scheduled_timestamp__lte=timezone_now(),
delivered=False)
if messages_to_deliver:
for message in messages_to_deliver:
with transaction.atomic():
do_send_messages([self.construct_message(message)])
message.delivered = True
message.save(update_fields=['delivered'])
cur_time = timezone_now()
time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0)
sleep_time = (time_next_min - cur_time).total_seconds()
time.sleep(sleep_time)
cur_time = timezone_now()
time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0)
sleep_time = (time_next_min - cur_time).total_seconds()
time.sleep(sleep_time)