mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
- Added new libraries to Pipfile: httpx and click - Refactored the file structure - Added new functionality in logging.py to set log level - README.md now includes information about running the server, running the client, and a sample configuration file - Started working on checks logic
38 lines
893 B
Python
38 lines
893 B
Python
from fastapi import Depends, FastAPI, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
from argos.server import queries, models
|
|
from argos import schemas
|
|
from argos.server.database import SessionLocal, engine
|
|
from argos.logging import logger
|
|
|
|
models.Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
# Dependency
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def read_config_and_populate_db():
|
|
# XXX Get filename from environment.
|
|
config = schemas.config.from_yaml("config.yaml")
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
queries.update_from_config(db, config)
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
@app.get("/tasks", response_model=list[schemas.Task])
|
|
async def read_tasks(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|
users = queries.list_tasks(db, limit)
|
|
return users
|