Added api to tests
This commit is contained in:
parent
c25d099f0c
commit
051f0e8ed0
1 changed files with 44 additions and 16 deletions
|
@ -1,13 +1,42 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from handler.action_queue import ActionQueue
|
from handler.action_queue import ActionQueue
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
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():
|
async def idle_a():
|
||||||
while True:
|
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)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,23 +51,22 @@ async def action_b():
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
logging.info("Ended action B")
|
logging.info("Ended action B")
|
||||||
|
|
||||||
|
@app.post("/idle_a")
|
||||||
async def main():
|
async def api_idle_a():
|
||||||
logging.info("Starting main")
|
|
||||||
|
|
||||||
await action_a()
|
|
||||||
|
|
||||||
logging.info("Starting action queue")
|
|
||||||
queue = ActionQueue()
|
|
||||||
|
|
||||||
await queue.set_idle_action(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)
|
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 queue.add_action_to_queue(action_b)
|
||||||
|
|
||||||
await asyncio.sleep(10)
|
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(main())
|
|
||||||
|
|
Loading…
Reference in a new issue