Skip to content

Commit

Permalink
separate app from main
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Jun 4, 2024
1 parent bf9a7ed commit e8727e8
Showing 1 changed file with 7 additions and 38 deletions.
45 changes: 7 additions & 38 deletions src/config_service/__main__.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
from argparse import ArgumentParser

from fastapi import dependencies

from . import __version__
from .constants import ENDPOINTS

try:
import redis
import uvicorn
from dodal.beamlines.beamline_parameters import (
BEAMLINE_PARAMETER_PATHS,
GDABeamlineParameters,
)
from fastapi import FastAPI

app = FastAPI()
valkey = redis.Redis(host="localhost", port=6379, decode_responses=True)
import redis # noqa
import uvicorn # noqa
from fastapi import FastAPI # noqa

server_dependencies_exist = True
except ImportError:
server_dependencies_exist = False

__all__ = ["main"]

BEAMLINE_PARAM_PATH = ""
BEAMLINE_PARAMS: GDABeamlineParameters | None = None


@app.get(ENDPOINTS.BL_PARAM + "{item_id}")
def beamlineparameter(item_id: str):
assert BEAMLINE_PARAMS is not None
return {item_id: BEAMLINE_PARAMS.params.get(item_id)}


@app.post(ENDPOINTS.FEATURE + "{item_id}")
def set_featureflag(item_id: str, value: bool):
return {"success": valkey.set(item_id, int(value))}


@app.get(ENDPOINTS.FEATURE + "{item_id}")
def get_featureflag(item_id: str):
ret = int(valkey.get(item_id)) # type: ignore
return {item_id: bool(ret) if ret is not None else None, "raw": ret}
__all__ = ["main"]


def main():
Expand All @@ -57,12 +28,10 @@ def main():
"importing the client, you must install this package with [server] "
"optional dependencies"
)
if args.dev:
BEAMLINE_PARAM_PATH = "tests/test_data/beamline_parameters.txt"
else:
BEAMLINE_PARAM_PATH = BEAMLINE_PARAMETER_PATHS["i03"]
BEAMLINE_PARAMS = GDABeamlineParameters.from_file(BEAMLINE_PARAM_PATH)
uvicorn.run(app="config_service.__main__:app", host="0.0.0.0", port=8555)
from .app import main

main(args)


# test with: python -m config_service
Expand Down

0 comments on commit e8727e8

Please sign in to comment.