Skip to content

Commit

Permalink
Merge pull request SmileyChris#14 from alepane21/master
Browse files Browse the repository at this point in the history
- added a cron mode to the management commands
  • Loading branch information
paltman committed Jan 20, 2014
2 parents 31a88b9 + adafd65 commit 836398e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
17 changes: 8 additions & 9 deletions mailer/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ def prioritize():
"""

while True:
while Message.objects.high_priority().count() or Message.objects.medium_priority().count():
while Message.objects.high_priority().count():
for message in Message.objects.high_priority().order_by("when_added"):
while Message.objects.high_priority().using('default').count() or Message.objects.medium_priority().using('default').count():
while Message.objects.high_priority().using('default').count():
for message in Message.objects.high_priority().using('default').order_by("when_added"):
yield message
while Message.objects.high_priority().count() == 0 and Message.objects.medium_priority().count():
yield Message.objects.medium_priority().order_by("when_added")[0]
while Message.objects.high_priority().count() == 0 and Message.objects.medium_priority().count() == 0 and Message.objects.low_priority().count():
yield Message.objects.low_priority().order_by("when_added")[0]
if Message.objects.non_deferred().count() == 0:
while Message.objects.high_priority().using('default').count() == 0 and Message.objects.medium_priority().using('default').count():
yield Message.objects.medium_priority().using('default').order_by("when_added")[0]
while Message.objects.high_priority().using('default').count() == 0 and Message.objects.medium_priority().using('default').count() == 0 and Message.objects.low_priority().using('default').count():
yield Message.objects.low_priority().using('default').order_by("when_added")[0]
if Message.objects.non_deferred().using('default').count() == 0:
break


def send_all():
"""
Send all eligible messages in the queue.
Expand Down
12 changes: 11 additions & 1 deletion mailer/management/commands/retry_deferred.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from optparse import make_option

from django.core.management.base import NoArgsCommand
from django.db import connection
Expand All @@ -8,9 +9,18 @@

class Command(NoArgsCommand):
help = "Attempt to resend any deferred mail."
base_options = (
make_option('-c', '--cron', default=0, type='int',
help='If 1 don\'t print messagges, but only errors.'
),
)
option_list = NoArgsCommand.option_list + base_options

def handle_noargs(self, **options):
logging.basicConfig(level=logging.DEBUG, format="%(message)s")
if options['cron'] == 0:
logging.basicConfig(level=logging.DEBUG, format="%(message)s")
else:
logging.basicConfig(level=logging.ERROR, format="%(message)s")
count = Message.objects.retry_deferred() # @@@ new_priority not yet supported
logging.info("%s message(s) retried" % count)
connection.close()
12 changes: 11 additions & 1 deletion mailer/management/commands/send_mail.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from optparse import make_option

from django.conf import settings
from django.core.management.base import NoArgsCommand
Expand All @@ -13,9 +14,18 @@

class Command(NoArgsCommand):
help = "Do one pass through the mail queue, attempting to send all mail."
base_options = (
make_option('-c', '--cron', default=0, type='int',
help='If 1 don\'t print messagges, but only errors.'
),
)
option_list = NoArgsCommand.option_list + base_options

def handle_noargs(self, **options):
logging.basicConfig(level=logging.DEBUG, format="%(message)s")
if options['cron'] == 0:
logging.basicConfig(level=logging.DEBUG, format="%(message)s")
else:
logging.basicConfig(level=logging.ERROR, format="%(message)s")
logging.info("-" * 72)
# if PAUSE_SEND is turned on don't do anything.
if not PAUSE_SEND:
Expand Down

0 comments on commit 836398e

Please sign in to comment.