def test_perform_tick_skip(self, mock_check_rule): """Tests performing a single clock tick with rules that should be skipped.""" job_test_utils.create_clock_rule(is_active=False) job_test_utils.create_clock_rule(rule_type='NOT_CLOCK') clock.perform_tick() self.assertFalse(mock_check_rule.called)
def test_perform_tick(self, mock_check_rule): """Tests performing a single clock tick.""" job_test_utils.create_clock_rule() job_test_utils.create_clock_rule() clock.perform_tick() self.assertEqual(mock_check_rule.call_count, 2)
def test_perform_tick_skip(self, mock_check_rule): '''Tests performing a single clock tick with rules that should be skipped.''' job_test_utils.create_clock_rule(is_active=False) job_test_utils.create_clock_rule(rule_type=u'NOT_CLOCK') clock.perform_tick() self.assertFalse(mock_check_rule.called)
def test_perform_tick(self, mock_check_rule): '''Tests performing a single clock tick.''' job_test_utils.create_clock_rule() job_test_utils.create_clock_rule() clock.perform_tick() self.assertEqual(mock_check_rule.call_count, 2)
def test_perform_tick_error(self, mock_check_rule): """Tests performing a clock tick will continue even when rules fail.""" mock_check_rule.side_effect = ClockEventError() job_test_utils.create_clock_rule() job_test_utils.create_clock_rule() clock.perform_tick() self.assertEqual(mock_check_rule.call_count, 2)
def test_perform_tick_error(self, mock_check_rule): '''Tests performing a clock tick will continue even when rules fail.''' mock_check_rule.side_effect = ClockEventError() job_test_utils.create_clock_rule() job_test_utils.create_clock_rule() clock.perform_tick() self.assertEqual(mock_check_rule.call_count, 2)
def handle(self, **options): '''See :meth:`django.core.management.base.BaseCommand.handle`. This method starts the Scale clock. ''' self.running = True # Register a listener to handle clean shutdowns signal.signal(signal.SIGTERM, self._onsigterm) logger.info(u'Command starting: scale_clock') while self.running: secs_passed = 0 try: if not self.job_id: self._init_clock() else: self._check_clock() started = now() clock.perform_tick() ended = now() secs_passed = (ended - started).total_seconds() except: logger.exception(u'Clock encountered error') finally: if self.running: # If process time takes less than throttle time, throttle if secs_passed < self.throttle: # Delay until full throttle time reached delay = math.ceil(self.throttle - secs_passed) logger.debug(u'Pausing for %i seconds', delay) time.sleep(delay) logger.info(u'Command completed: scale_clock') # Clock never successfully finishes, it should always run sys.exit(1)
def handle(self, **options): """See :meth:`django.core.management.base.BaseCommand.handle`. This method starts the Scale clock. """ self.running = True # Register a listener to handle clean shutdowns signal.signal(signal.SIGTERM, self._onsigterm) logger.info('Command starting: scale_clock') while self.running: secs_passed = 0 try: if not self.job_id: self._init_clock() else: self._check_clock() started = now() clock.perform_tick() ended = now() secs_passed = (ended - started).total_seconds() except: logger.exception('Clock encountered error') finally: if self.running: # If process time takes less than throttle time, throttle if secs_passed < self.throttle: # Delay until full throttle time reached delay = math.ceil(self.throttle - secs_passed) logger.debug('Pausing for %i seconds', delay) time.sleep(delay) logger.info('Command completed: scale_clock') # Clock never successfully finishes, it should always run sys.exit(1)