[+] Added a longer scheduler.

Soon will be implemented a modpack update check.
This commit is contained in:
Charles Le Maux 2024-09-20 09:59:21 +02:00
parent bf49e5c038
commit 29b42be411
2 changed files with 11 additions and 3 deletions

8
app.py
View File

@ -188,11 +188,15 @@ app.register_blueprint(apiBP)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Background Scheduler") parser = argparse.ArgumentParser(description="Background Scheduler")
parser.add_argument('--interval', type=int, default=10, help="Interval in minutes") (parser.add_argument
('--servers-interval', type=int, default=10, help="Interval to check for idle servers. (in minutes)"))
(parser.add_argument
('--modpacks-interval', type=int, default=48, help="Interval to check for modpack updates. (in hours)"))
args = parser.parse_args() args = parser.parse_args()
scheduler = BackgroundScheduler() scheduler = BackgroundScheduler()
scheduler.add_job(generic_executor.scheduled_actions, 'interval', minutes=args.interval) scheduler.add_job(generic_executor.scheduled_actions_short, 'interval', minutes=args.servers_interval)
scheduler.add_job(generic_executor.scheduled_actions_long, 'interval', hours=args.modpacks_interval)
scheduler.start() scheduler.start()
run_simple('0.0.0.0', 3000, app, use_debugger=False, use_reloader=False) run_simple('0.0.0.0', 3000, app, use_debugger=False, use_reloader=False)

View File

@ -328,9 +328,13 @@ def run_command(user: UserRecord, command: str, name: str) -> tuple[HTTPStatus,
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error executing command: {command} || {str(e)}" return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error executing command: {command} || {str(e)}"
def scheduled_actions() -> None: def scheduled_actions_short() -> None:
mc_manager.check_servers_idle() mc_manager.check_servers_idle()
def scheduled_actions_long() -> None:
pass
if __name__ == "__main__": if __name__ == "__main__":
pass pass