Exemplo n.º 1
0
def run():  # pragma: no cover
    assert 'DJANGO_SETTINGS_MODULE' in os.environ, "DJANGO_SETTINGS_MODULE is missing from environment, you must set if before running this worker"
    logging.info("os.environ['DJANGO_SETTINGS_MODULE']: %s" %
                 os.environ['DJANGO_SETTINGS_MODULE'])

    cwd = os.getcwd()

    if cwd not in sys.path:  # pragma: no cover
        sys.path.append(cwd)

    # Show a debugging info on console
    logging.debug("__file__ = %s", __file__)
    logging.debug("sys.version = %s", sys.version)
    logging.debug("os.getpid() = %s", os.getpid())
    logging.debug("os.getcwd() = %s", cwd)
    logging.debug("os.curdir = %s", os.curdir)
    logging.debug("sys.path:\n\t%s", "\n\t".join(sys.path))
    logging.debug("PYTHONPATH:\n\t%s",
                  "\n\t".join(os.environ.get('PYTHONPATH', "").split(';')))
    logging.debug("sys.modules.keys() = %s", repr(sys.modules.keys()))
    logging.debug("sys.modules.has_key('website') = %s", 'website'
                  in sys.modules)

    from django.conf import settings
    import django

    django.setup()
    logging.debug("settings.__dir__: %s", settings.__dir__())
    logging.debug("settings.DEBUG: %s", settings.DEBUG)

    from django_email_queue.models import QueuedEmailMessage

    while True:
        QueuedEmailMessage.send_queued(10)
        seconds = settings.EMAIL_QUEUE_SLEEP_TIME
        logging.debug("Will sleep for %s seconds", seconds)
        sleep(seconds)
Exemplo n.º 2
0
 def test_send_queued(self, send):
     QueuedEmailMessageFactory.create_batch(
         11, status=QueuedEmailMessageStatus.posted)
     QueuedEmailMessageFactory.create_batch(5)
     QueuedEmailMessage.send_queued()
     self.assertEqual(5, send.call_count)
Exemplo n.º 3
0
 def test_send_queued_limit(self, send):
     QueuedEmailMessageFactory.create_batch(5)
     QueuedEmailMessage.send_queued(3)
     self.assertEqual(3, send.call_count)