From 10d949001526440f2a73cd365f28c147db0cd5e7 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 13 Jul 2018 21:46:27 +0200 Subject: [PATCH] [enh] support restart --- run.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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)