diff --git a/run.py b/run.py index 1bc6f5c..cead0a1 100644 --- a/run.py +++ b/run.py @@ -30,6 +30,15 @@ COMMUNITY_APPS_LIST = "https://app.yunohost.org/community.json" APPS_LIST = [OFFICAL_APPS_LIST, COMMUNITY_APPS_LIST] +def reset_pending_jobs(): + Job.update(state="scheduled").where(Job.state == "running").execute() + + +def reset_busy_workers(): + # XXX when we'll have distant workers that might break those + Worker.update(state="available").execute() + + async def initialize_app_list(): if not os.path.exists("lists"): os.makedirs("lists") @@ -208,6 +217,9 @@ async def index(request): if __name__ == "__main__": subscriptions = defaultdict(list) + reset_pending_jobs() + reset_busy_workers() + app.add_task(initialize_app_list()) app.add_task(jobs_dispatcher()) app.run('localhost', port=5000, debug=True)