Example #1
0
 def test_locked_timeoutbug(self):
     lock = FileLock(engine.LOCK_PATH)
     lock.unique_name = 'mailer-test'
     lock.acquire()
     # We want to emulate the lock acquiring taking no time, so the next
     # three calls to time.time() always return 0 (then set it back to the
     # real function).
     original_time = time.time
     global time_call_count
     time_call_count = 0
     def fake_time():
         global time_call_count
         time_call_count = time_call_count + 1
         if time_call_count >= 3:
             time.time = original_time
         return 0
     time.time = fake_time
     try:
         engine.send_all()
         self.output.seek(0)
         self.assertEqual(self.output.readlines()[-1].strip(),
                          'Lock already in place. Exiting.')
     finally:
         lock.release()
         time.time = original_time
Example #2
0
    def handle_noargs(self, verbosity, block_size, count, **options):
        # If this is just a count request the just calculate, report and exit.
        if count:
            queued = models.QueuedMessage.objects.non_deferred().count()
            deferred = models.QueuedMessage.objects.non_deferred().count()
            sys.stdout.write('%s queued message%s (and %s deferred message%s).'
                             '\n' % (queued, queued != 1 and 's' or '',
                                     deferred, deferred != 1 and 's' or ''))
            sys.exit()

        # Send logged messages to the console.
        logger = logging.getLogger('django_mailer')
        handler = create_handler(verbosity)
        logger.addHandler(handler)

        # if PAUSE_SEND is turned on don't do anything.
        if not settings.PAUSE_SEND:
            if EMAIL_BACKEND_SUPPORT:
                send_all(block_size, backend=settings.MAILER_BACKEND)
            else:
                send_all(block_size)
        else:
            logger = logging.getLogger('django_mailer.commands.send_mail')
            logger.warning("Sending is paused, exiting without sending "
                           "queued mail.")

        logger.removeHandler(handler)

        # Stop superfluous "unexpected EOF on client connection" errors in
        # Postgres log files caused by the database connection not being
        # explicitly closed.
        connection.close()
Example #3
0
    def handle_noargs(self, verbosity, block_size, count, **options):
        # If this is just a count request the just calculate, report and exit.
        if count:
            queued = models.QueuedMessage.objects.non_deferred().count()
            deferred = models.QueuedMessage.objects.deferred().count()
            sys.stdout.write('%s queued message%s (and %s deferred message%s).'
                             '\n' % (queued, queued != 1 and 's' or '',
                                     deferred, deferred != 1 and 's' or ''))
            sys.exit()

        # Send logged messages to the console.
        logger = logging.getLogger('django_mailer')
        handler = create_handler(verbosity)
        logger.addHandler(handler)

        # if PAUSE_SEND is turned on don't do anything.
        if not settings.PAUSE_SEND:
            if EMAIL_BACKEND_SUPPORT:
                send_all(block_size, backend=settings.USE_BACKEND)
            else:
                send_all(block_size)
        else:
            logger = logging.getLogger('django_mailer.commands.send_mail')
            logger.warning("Sending is paused, exiting without sending "
                           "queued mail.")

        logger.removeHandler(handler)

        # Stop superfluous "unexpected EOF on client connection" errors in
        # Postgres log files caused by the database connection not being
        # explicitly closed.
        connection.close()
Example #4
0
 def handle_noargs(self, **options):
     logging.basicConfig(level=logging.DEBUG, format="%(message)s")
     logging.info("-" * 72)
     # if PAUSE_SEND is turned on don't do anything.
     if not PAUSE_SEND:
         send_all()
     else:
         logging.info("sending is paused, quitting.")
 def test_locked(self):
     # Acquire the lock so that send_all will fail.
     engine.send_all()
     self.output.seek(0)
     self.assertEqual(self.output.readlines()[-1].strip(),
                      'Lock already in place. Exiting.')
     # Try with a timeout.
     settings.LOCK_WAIT_TIMEOUT = .1
     engine.send_all()
     self.output.seek(0)
     self.assertEqual(self.output.readlines()[-1].strip(),
                      'Waiting for the lock timed out. Exiting.')
Example #6
0
 def test_locked(self):
     # Acquire the lock so that send_all will fail.
     engine.send_all()
     self.output.seek(0)
     self.assertEqual(self.output.readlines()[-1].strip(),
                      'Lock already in place. Exiting.')
     # Try with a timeout.
     settings.LOCK_WAIT_TIMEOUT = .1
     engine.send_all()
     self.output.seek(0)
     self.assertEqual(self.output.readlines()[-1].strip(),
                      'Waiting for the lock timed out. Exiting.')
Example #7
0
 def test_locked(self):
     # Acquire the lock (under a different unique name) so that send_all
     # will fail.
     lock = FileLock(engine.LOCK_PATH)
     lock.unique_name = 'mailer-test'
     lock.acquire()
     try:
         engine.send_all()
         self.output.seek(0)
         self.assertEqual(self.output.readlines()[-1].strip(),
                          'Lock already in place. Exiting.')
         # Try with a timeout.
         settings.LOCK_WAIT_TIMEOUT = .1
         engine.send_all()
         self.output.seek(0)
         self.assertEqual(self.output.readlines()[-1].strip(),
                          'Waiting for the lock timed out. Exiting.')
     finally:
         # Always release the test lock.
         lock.release()
    def test_locked_timeoutbug(self):
        # We want to emulate the lock acquiring taking no time, so the next
        # three calls to time.time() always return 0 (then set it back to the
        # real function).
        original_time = time.time
        global time_call_count
        time_call_count = 0

        def fake_time():
            global time_call_count
            time_call_count = time_call_count + 1
            if time_call_count >= 3:
                time.time = original_time
            return 0

        time.time = fake_time
        try:
            engine.send_all()
            self.output.seek(0)
            self.assertEqual(self.output.readlines()[-1].strip(),
                             'Lock already in place. Exiting.')
        finally:
            time.time = original_time
Example #9
0
 def test_locked(self):
     # Acquire the lock so that send_all will fail.
     engine.send_all()
     self.output.seek(0)
     self.assertEqual(self.output.readlines()[-1].strip(),
                      'Lock already in place. Exiting.')