diff --git a/README.rst b/README.rst index 4a9fc897..ba66fa39 100644 --- a/README.rst +++ b/README.rst @@ -457,6 +457,11 @@ Management Commands | ``--lockfile`` or ``-L`` | Full path to file used as lock file. Defaults to | | | ``/tmp/post_office.lock`` | +---------------------------+--------------------------------------------------+ +| ``--exit-after-batch`` or | Exit the command after sending one batch of | +| ``-x`` | emails. By combining BATCH_SIZE and crontab, | +| | you can send emails through servers with small | +| | throttling values. | ++---------------------------+--------------------------------------------------+ * ``cleanup_mail`` - delete all emails created before an X number of days diff --git a/post_office/management/commands/send_queued_mail.py b/post_office/management/commands/send_queued_mail.py index ab739e9d..e5e314c5 100644 --- a/post_office/management/commands/send_queued_mail.py +++ b/post_office/management/commands/send_queued_mail.py @@ -34,6 +34,11 @@ def add_arguments(self, parser): type=int, help='"0" to log nothing, "1" to only log errors', ) + parser.add_argument( + '-x', '--exit-after-batch', + action='store_true', + help='Exit script after sending one batch of emails', + ) def handle(self, *args, **options): logger.info('Acquiring lock for sending queued emails at %s.lock' % @@ -53,6 +58,9 @@ def handle(self, *args, **options): # Close DB connection to avoid multiprocessing errors connection.close() + if options.get('exit_after_batch'): + break + if not Email.objects.filter(status=STATUS.queued) \ .filter(Q(scheduled_time__lte=now()) | Q(scheduled_time=None)).exists(): break