Fix serve command: handle outside asyncio.run() to avoid nested loop error
uvicorn manages its own event loop, so cmd_serve must not be called inside asyncio.run(). Also deduplicate redundant VectorIndex branching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6374aea0a2
commit
792dbceab5
1 changed files with 11 additions and 15 deletions
|
|
@ -319,14 +319,8 @@ def cmd_serve(args):
|
|||
database=config.storage.neo4j_database,
|
||||
)
|
||||
|
||||
# VectorIndex requires ChromaDB directory — skip for memory backend in tests
|
||||
vector_index = None
|
||||
if backend != "memory":
|
||||
from aucourt_ingest.storage.vector_index import VectorIndex
|
||||
vector_index = VectorIndex(str(config.storage.chromadb_dir))
|
||||
else:
|
||||
from aucourt_ingest.storage.vector_index import VectorIndex
|
||||
vector_index = VectorIndex(str(config.storage.chromadb_dir))
|
||||
from aucourt_ingest.storage.vector_index import VectorIndex
|
||||
vector_index = VectorIndex(str(config.storage.chromadb_dir))
|
||||
|
||||
from aucourt_ingest.api.app import create_app
|
||||
app = create_app(graph_db, vector_index, max_tokens)
|
||||
|
|
@ -336,10 +330,7 @@ def cmd_serve(args):
|
|||
uvicorn.run(app, host=host, port=port)
|
||||
|
||||
|
||||
async def async_main():
|
||||
parser = build_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
async def async_main(args):
|
||||
if not args.mode:
|
||||
parser.print_help()
|
||||
return
|
||||
|
|
@ -354,13 +345,18 @@ async def async_main():
|
|||
await cmd_audit(args)
|
||||
elif args.mode == "process":
|
||||
await cmd_process(args)
|
||||
elif args.mode == "serve":
|
||||
cmd_serve(args)
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
||||
asyncio.run(async_main())
|
||||
parser = build_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.mode == "serve":
|
||||
cmd_serve(args)
|
||||
return
|
||||
|
||||
asyncio.run(async_main(args))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue