Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ WORKDIR /app
USER app
EXPOSE 8000

CMD ["sh", "-c", "uvicorn api.main:app --host ${HOST} --port ${PORT} --log-level info"]
CMD ["sh", "-c", "uvicorn api.main:app_factory --factory --host ${HOST} --port ${PORT} --log-level info --workers ${API_WORKERS:-4}"]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

2 changes: 1 addition & 1 deletion packages/api/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ ENV HOST=0.0.0.0 PORT=8000 DEBUG=true

EXPOSE 8000

CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload", "--log-level", "info"]
CMD ["uvicorn", "api.main:app_factory", "--factory", "--host", "0.0.0.0", "--port", "8000", "--reload", "--log-level", "info"]
6 changes: 5 additions & 1 deletion packages/api/run_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
host = os.getenv("HOST", "127.0.0.1")
port = int(os.getenv("PORT", "8000"))
debug = os.getenv("DEBUG", "false").lower() == "true"
workers = int(os.getenv("API_WORKERS", "4"))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default should be "1" not "4" until SQLite concurrency is addressed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, obviously you're right. In order for this PR to be complete, it should address the concurrent writes issue (moving away from SQLite? serializing?). So we can either do this one as ground work and address these issues later, or just postpone this PR until there's a fuller solution. This is your baby - your call. Feel free to edit this PR with workers=1 or just discard it to come back to it later. I'm fine either way :-)


print(f"Starting Shelly Manager API on {host}:{port}")
print(f"Debug mode: {debug}")
print(f"Workers: {1 if debug else workers} ({'reload mode' if debug else 'multi-worker'})")
print(f"OpenAPI docs: http://{host}:{port}/docs")
print(f"OpenAPI JSON: http://{host}:{port}/openapi.json")
print(f"Health check: http://{host}:{port}/api/health")

uvicorn.run(
"api.main:app",
"api.main:app_factory",
host=host,
port=port,
factory=True,
workers=1 if debug else workers,
reload=debug,
log_level="info" if not debug else "debug",
)
3 changes: 3 additions & 0 deletions packages/api/src/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ async def lifespan(app: Litestar) -> AsyncGenerator[None, None]:


app = create_app()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're going to use app_factory, can we remove this one?


def app_factory() -> Litestar:
return create_app()
Loading