Initial vLLM agent strategy
This commit is contained in:
58
app/main.py
Normal file
58
app/main.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from flask import Flask, jsonify
|
||||
|
||||
from app.clients.modelhub import ModelHubClient
|
||||
from app.scheduler.loop import StrategyLoop
|
||||
from app.settings import load_settings
|
||||
from app.shutdown import install_signal_handlers, stop_event
|
||||
from app.storage.db import connect
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s")
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_app() -> Flask:
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return jsonify({"status": "ok"}), 200
|
||||
|
||||
@app.get("/status")
|
||||
def status():
|
||||
return jsonify({"status": "ok", "stopping": stop_event.is_set()}), 200
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def main():
|
||||
install_signal_handlers()
|
||||
settings = load_settings(require_secrets=True)
|
||||
LOG.info(
|
||||
"starting vLLM agent strategy dry_run=%s inject_strategy_id=%s strategy_field=%s db=%s",
|
||||
settings.submit_dry_run,
|
||||
settings.inject_strategy_id,
|
||||
settings.contest_task_strategy_field,
|
||||
settings.db_path,
|
||||
)
|
||||
conn = connect(settings.db_path)
|
||||
client = ModelHubClient(settings)
|
||||
loop = StrategyLoop(settings, __import__("app.storage.repositories", fromlist=["Repository"]).Repository(conn), client)
|
||||
worker = threading.Thread(target=loop.run_forever, args=(stop_event,), name="strategy-loop", daemon=True)
|
||||
worker.start()
|
||||
app = create_app()
|
||||
try:
|
||||
app.run(host=settings.host, port=settings.port, threaded=True)
|
||||
finally:
|
||||
stop_event.set()
|
||||
worker.join(timeout=25)
|
||||
conn.close()
|
||||
LOG.info("shutdown complete")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user