def test_get_two_seg_until_next(self): dispatcher = Dispatcher() now = datetime.now() after_now = now + timedelta(minutes=1) n = Heartbeat(dispatcher, 1, 2, after_now.strftime('%H:%M')) one = n.get_seg_until_next() two = n.get_seg_until_next() self.assertTrue(two - one < 2)
def test_get_seg_until_next(self): dispatcher = Dispatcher() now = datetime.now() after_now = now + timedelta(minutes=1) n = Heartbeat(dispatcher, 1, 2, after_now.strftime('%H:%M')) seg = n.get_seg_until_next() self.assertLess(seg, 60) self.assertGreater(seg, 0) now = datetime.now() after_now = now - timedelta(hours=1) n = Heartbeat(dispatcher, 1, 2, after_now.strftime('%H:%M')) seg = n.get_seg_until_next() self.assertTrue(seg > 22 * 3600) self.assertTrue(seg < 24 * 3600)
def test_init(self): dispatcher = Dispatcher() time_ok = ['10:10', '23:04', '1:2'] time_ko = ['10-10', '23:12234', 'doce', '1:_2', 'tonight'] for t in time_ok: Heartbeat(dispatcher, 1, 2, t) for t in time_ko: self.assertRaises(ValueError, Heartbeat, dispatcher, 1, 2, t)
def get_heartbeat(): """ Get Galicaster Heartbeat from the App Context """ # TODO Review if 'heartbeat' not in __galicaster_context: heartbeat = Heartbeat(get_dispatcher(), get_conf().get_int('heartbeat', 'short'), get_conf().get_int('heartbeat', 'long'), get_conf().get('heartbeat', 'night')) __galicaster_context['heartbeat'] = heartbeat return __galicaster_context['heartbeat']
def get_heartbeat(): """Creates if necessary and retrieves Galicaster Heartbeat from the App Context. Returns: Heartbeat: the heartbeat instance in galicaster context. """ from galicaster.scheduler.heartbeat import Heartbeat # TODO Review if 'heartbeat' not in __galicaster_context: heartbeat = Heartbeat( get_dispatcher(), get_conf().get_int('heartbeat', 'short', 10), get_conf().get_int('heartbeat', 'long', 60), get_conf().get_hour('heartbeat', 'night', '00:00'), get_logger()) __galicaster_context['heartbeat'] = heartbeat return __galicaster_context['heartbeat']
def test_get_seg_until_next_now(self): dispatcher = Dispatcher() now = datetime.now() n = Heartbeat(dispatcher, 1, 2, now.strftime('%H:%M')) self.assertTrue(n.get_seg_until_next(), 24 * 60 * 60)
def test_get_seg_until_next_now(self): dispatcher = Dispatcher() now = datetime.now() n = Heartbeat(dispatcher, 1, 2, now.strftime('%H:%M')) self.assertTrue(n.get_seg_until_next(), 24*60*60)