def test_repeat(self): repeats = 3 scheduler.repeat(self.inc_counter, timedelta(seconds=0), max_repeats=repeats) time.sleep(0.1) self.assertEqual(self.count, repeats)
def test_interval(self): repeats = 3 delay = 0.01 scheduler.repeat(self.inc_counter, timedelta(seconds=delay), max_repeats=repeats) for r in range(repeats): self.assertLessEqual(self.count, r + 1) time.sleep(delay)
def test_exception_recovery(self): repeats = 3 def foo(): self.count += 1 raise RuntimeError('foo!') scheduler.repeat(foo, timedelta(seconds=0), max_repeats=repeats) time.sleep(0.1) self.assertEqual(self.count, repeats)
def test_cancel(self): repeats = 3 delay = 0.1 cancel_fn = scheduler.repeat(self.inc_counter, timedelta(seconds=delay), max_repeats=repeats) cancel_fn() time.sleep(3) self.assertEqual(self.count, 1)
def broadcast(socketio, secs_history, update_rate=BROADCAST_RATE_SECS): """ Broadcast updates via socketui """ # cancel existing schedulers for cancel_fn in BROADCAST_LOOPS: cancel_fn() BROADCAST_LOOPS.clear() # start new scheduler def broadcast(): socketio.send(latest(secs_history)) BROADCAST_LOOPS.append( scheduler.repeat( broadcast, interval=datetime.timedelta(seconds=update_rate) ) )
def start_polling(): """ Start polling starlink for data, and performing perioic speedtests """ scheduler.repeat( _update_starlink_status, interval=datetime.timedelta(seconds=STARLINK_REFRESH_SECS) ) scheduler.repeat( _update_starlink_history, interval=datetime.timedelta(seconds=STARLINK_HISTORY_REFRESH_SECS) ) scheduler.repeat( _update_speedtest, interval=datetime.timedelta(minutes=SPEEDTEST_REFRESH_MINS) )