28def scheduler_function(start_after_from: int, start_after_to: int, every_from: int, every_to: int, callback: Callable):
29 """Run the checker periodically. The function never returns.
30
31 Parameters:
32 * start_after_from and start_after_to: when to call "callback" for the first on the Redis instance
33 * every_from and every_to: after the first call, how often to call "callback"
34
35 There is no issue:
36 * to call this function is multiple workers
37 * to kill workers at any time as long there is one at least one worker
38 """
39 scheduler_now_script = SCHEDULER_LUA.open().read()
40 while True:
41
42
43
44
45 script = lua_script_storage(get_redis_client(), scheduler_now_script)
46 call_now, wait_time = script(args=[start_after_from, start_after_to, every_from, every_to])
47
48
49 if call_now:
50
51 try:
52 callback()
53 except Exception:
54 logger.exception("Error calling the embedded checker")
55
56 logger.info("Next call to the checker in %s seconds", wait_time)
57
58 time.sleep(wait_time)