Skip to content

Commit

Permalink
reload server
Browse files Browse the repository at this point in the history
working except for db watcher
  • Loading branch information
alex-dixon committed Aug 7, 2024
1 parent 9538bfc commit 9e95e9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/ell/studio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def main():
parser.add_argument("--dev", action="store_true", help="Run in development mode")
args = parser.parse_args()

app = create_app(args.storage_dir)

if not args.dev:
app = create_app()
# In production mode, serve the built React app
static_dir = os.path.join(os.path.dirname(__file__), "static")
app.mount("/", StaticFiles(directory=static_dir, html=True), name="static")
Expand Down Expand Up @@ -68,9 +68,15 @@ async def db_watcher(db_path, app):
# Start the database watcher
loop = asyncio.new_event_loop()

config = uvicorn.Config(app=app, port=args.port, loop=loop)
server = uvicorn.Server(config)
loop.create_task(server.serve())
# config = uvicorn.Config(app=app, port=args.port, loop=loop,reload=True,#if args.dev else False,
# reload_delay=1)
# server = uvicorn.Server(config)
uvicorn.run("ell.studio.data_server:create_app",
reload=True,
reload_delay=5,
host=args.host,
port=args.port)
# loop.create_task(server.serve())
loop.create_task(db_watcher(db_path, app))
loop.run_forever()

Expand Down
9 changes: 7 additions & 2 deletions src/ell/studio/data_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import asyncio
import json
from argparse import ArgumentParser

logger = logging.getLogger(__name__)

Expand All @@ -28,9 +29,13 @@ async def broadcast(self, message: str):
print(f"Broadcasting message to {connection} {message}")
await connection.send_text(message)

def create_app():
parser = ArgumentParser(description="ELL Studio Data Server")
parser.add_argument("--storage-dir", default=os.getcwd(),
help="Directory for filesystem serializer storage (default: current directory)")
args, _ = parser.parse_known_args()

def create_app(storage_dir: Optional[str] = None):
storage_path = storage_dir or os.environ.get("ELL_STORAGE_DIR") or os.getcwd()
storage_path = args.storage_dir or os.environ.get("ELL_STORAGE_DIR") or os.getcwd()
assert storage_path, "ELL_STORAGE_DIR must be set"
serializer = SQLiteStore(storage_path)

Expand Down

0 comments on commit 9e95e9a

Please sign in to comment.