Files
zulip/zerver/management/commands/print_email_delivery_backlog.py
Tim Abbott 8e7ce7cc79 python: Sort migrations/management command imports with isort.
This is a preparatory commit for using isort for sorting all of our
imports, merging changes to files where we can easily review the
changes as something we're happy with.

These are also files with relatively little active development, which
means we don't expect much merge conflict risk from these changes.
2020-01-14 13:07:47 -08:00

25 lines
718 B
Python

"""
Shows backlog count of ScheduledEmail
"""
from datetime import timedelta
from typing import Any
from django.core.management.base import BaseCommand
from django.utils.timezone import now as timezone_now
from zerver.models import ScheduledEmail
class Command(BaseCommand):
help = """Shows backlog count of ScheduledEmail
(The number of currently overdue (by at least a minute) email jobs)
This is run as part of the nagios health check for the deliver_email command.
Usage: ./manage.py print_email_delivery_backlog
"""
def handle(self, *args: Any, **options: Any) -> None:
print(ScheduledEmail.objects.filter(
scheduled_timestamp__lte=timezone_now()-timedelta(minutes=1)).count())