40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
|
|
import devplacepy_services.base.bootstrap
|
||
|
|
|
||
|
|
from contextlib import asynccontextmanager
|
||
|
|
|
||
|
|
from fastapi import FastAPI
|
||
|
|
|
||
|
|
from devplacepy.routers import devii
|
||
|
|
from devplacepy.services.devii import DeviiService
|
||
|
|
from devplacepy_services.base.service import BaseMicroservice, build_standard_app
|
||
|
|
from devplacepy_services.devii import store_brokers
|
||
|
|
from devplacepy_services.devii.store_routes import router as store_router
|
||
|
|
|
||
|
|
|
||
|
|
class DeviiMicroservice(BaseMicroservice):
|
||
|
|
name = "devii"
|
||
|
|
title = "Devii"
|
||
|
|
default_port = 10631
|
||
|
|
workers = 2
|
||
|
|
stateful = True
|
||
|
|
depends_on = ["database", "pubsub", "gateway"]
|
||
|
|
managed_services = [DeviiService()]
|
||
|
|
use_background = True
|
||
|
|
run_supervisor = True
|
||
|
|
|
||
|
|
@asynccontextmanager
|
||
|
|
async def lifespan(self, app: FastAPI):
|
||
|
|
await store_brokers.startup()
|
||
|
|
async with super(DeviiMicroservice, self).lifespan(app):
|
||
|
|
yield
|
||
|
|
await store_brokers.shutdown()
|
||
|
|
|
||
|
|
def build_app(self):
|
||
|
|
return build_standard_app(
|
||
|
|
self,
|
||
|
|
routers=[(store_router,), (devii.router, "/devii")],
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
_service = DeviiMicroservice()
|
||
|
|
app = _service.build_app()
|