Spaces:
Paused
Paused
File size: 1,604 Bytes
8d1819a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import asyncio
from datetime import datetime
import time
from python.helpers.task_scheduler import TaskScheduler
from python.helpers.print_style import PrintStyle
from python.helpers import errors
from python.helpers import runtime
SLEEP_TIME = 60
keep_running = True
pause_time = 0
async def run_loop():
global pause_time, keep_running
while True:
if runtime.is_development():
# Signal to container that the job loop should be paused
# if we are runing a development instance to avoid duble-running the jobs
try:
await runtime.call_development_function(pause_loop)
except Exception as e:
PrintStyle().error("Failed to pause job loop by development instance: " + errors.error_text(e))
if not keep_running and (time.time() - pause_time) > (SLEEP_TIME * 2):
resume_loop()
if keep_running:
try:
await scheduler_tick()
except Exception as e:
PrintStyle().error(errors.format_error(e))
await asyncio.sleep(SLEEP_TIME) # TODO! - if we lower it under 1min, it can run a 5min job multiple times in it's target minute
async def scheduler_tick():
# Get the task scheduler instance and print detailed debug info
scheduler = TaskScheduler.get()
# Run the scheduler tick
await scheduler.tick()
def pause_loop():
global keep_running, pause_time
keep_running = False
pause_time = time.time()
def resume_loop():
global keep_running, pause_time
keep_running = True
pause_time = 0
|