Initial import: sources, staging packages, build scripts and CI workflow
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import getopt
|
||||
from hyperdeck.application import HyperDeck
|
||||
import asyncio
|
||||
import uvicorn
|
||||
|
||||
|
||||
from hyperdeck.db import create_db_and_tables
|
||||
from hyperdeck.jsondb import jsonconverter
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
opts, args = getopt.getopt(sys.argv[1:], "c:o:")
|
||||
configfile = "config.json"
|
||||
for opt, arg in opts:
|
||||
if opt == "-h":
|
||||
print("test.py -c <config>")
|
||||
sys.exit()
|
||||
elif opt in ("-c"):
|
||||
configfile = arg
|
||||
|
||||
create_db_and_tables()
|
||||
|
||||
hApp = HyperDeck()
|
||||
hApp.load_config(configfile)
|
||||
|
||||
if os.path.exists("schedule.json"):
|
||||
logging.info("Found schedule.json, loading")
|
||||
conv = jsonconverter()
|
||||
conv.loadschedule()
|
||||
logging.info("Loading done, creating database")
|
||||
|
||||
hApp.schedule.saveItems(conv.schedule)
|
||||
|
||||
logging.info("Database ready, moving file")
|
||||
os.rename("schedule.json","schedule.json.bak")
|
||||
|
||||
|
||||
from hyperdeck.api import app as app_fastapi
|
||||
from hyperdeck.scheduler import app as app_rocketry
|
||||
|
||||
|
||||
|
||||
session = app_rocketry.session
|
||||
|
||||
|
||||
class Server(uvicorn.Server):
|
||||
def handle_exit(self, sig: int, frame) -> None:
|
||||
app_rocketry.session.shut_down()
|
||||
return super().handle_exit(sig, frame)
|
||||
|
||||
|
||||
async def app():
|
||||
server = Server(
|
||||
config=uvicorn.Config(
|
||||
app_fastapi, workers=1, host=["0.0.0.0", "::"], port=8180, loop="asyncio"
|
||||
)
|
||||
)
|
||||
|
||||
api = asyncio.create_task(server.serve())
|
||||
sched = asyncio.create_task(app_rocketry.serve())
|
||||
|
||||
await asyncio.wait([sched, api])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
asyncio.run(app())
|
||||
Reference in New Issue
Block a user