diff --git a/src/testing.py b/src/testing.py index f062b3e..40d164a 100644 --- a/src/testing.py +++ b/src/testing.py @@ -1,13 +1,42 @@ import asyncio + +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware from handler.action_queue import ActionQueue import logging logging.getLogger().setLevel(logging.INFO) +queue = ActionQueue() +app = FastAPI() + +origins = [ + "http://localhost", + "http://localhost:8000", + "http://raspberrypi", + "http://192.168.178.84:8000", + "http://192.168.178.84", +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + + async def idle_a(): while True: - logging.info("Idleling ...") + logging.info("Idleling AAA ...") + await asyncio.sleep(1) + + +async def idle_b(): + while True: + logging.info("Idleling BBB ...") await asyncio.sleep(1) @@ -22,23 +51,22 @@ async def action_b(): await asyncio.sleep(1) logging.info("Ended action B") - -async def main(): - logging.info("Starting main") - - await action_a() - - logging.info("Starting action queue") - queue = ActionQueue() - +@app.post("/idle_a") +async def api_idle_a(): await queue.set_idle_action(idle_a) - await asyncio.sleep(7) +@app.post("/idle_b") +async def api_idle_b(): + await queue.set_idle_action(idle_b) +@app.post("/idle_a") +async def api_idle_a(): + await queue.set_idle_action(idle_a) + +@app.post("/action_a") +async def api_action_a(): await queue.add_action_to_queue(action_a) + +@app.post("/action_b") +async def api_action_b(): await queue.add_action_to_queue(action_b) - - await asyncio.sleep(10) - - -asyncio.run(main())