Skip to content

Commit

Permalink
Merge pull request #49 from quantmind/ls-extra
Browse files Browse the repository at this point in the history
allow to set port
  • Loading branch information
lsbardel authored Nov 24, 2024
2 parents 7ef9b4b + 3ab5e13 commit 44d51f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions fluid/tools_fastapi/backdoor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from functools import partial
from typing import Any

from fastapi import FastAPI

from fluid.utils.backdoor import ConsoleManager


def setup(app: FastAPI) -> None:
console = ConsoleManager()
def setup(app: FastAPI, **kwargs: Any) -> None:
console = ConsoleManager(**kwargs)
app.add_event_handler("startup", partial(console.on_startup, app))
app.add_event_handler("shutdown", partial(console.on_cleanup, app))
12 changes: 4 additions & 8 deletions fluid/utils/backdoor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import sys
from dataclasses import dataclass
from functools import partial

import aioconsole
Expand All @@ -22,16 +23,11 @@ def get_default_banner(self):
return f"Python {sys.version} on {sys.platform}\n{cprt}\n{CONSOLE_MESSAGE}"


@dataclass
class ConsoleManager:
aio_console = None

def __init__(
self,
port: int = settings.AIO_BACKDOOR_PORT,
host: str = "0.0.0.0",
) -> None:
self.port = port
self.host = host
port: int = settings.AIO_BACKDOOR_PORT
host: str = "0.0.0.0"

async def on_startup(self, app) -> None:
self.aio_console = await aioconsole.start_interactive_server(
Expand Down
2 changes: 2 additions & 0 deletions tests/scheduler/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from fluid.scheduler import TaskManager, TaskScheduler
from fluid.scheduler.broker import RedisTaskBroker
from fluid.scheduler.endpoints import get_task_manger, setup_fastapi
from fluid.tools_fastapi import backdoor
from tests.scheduler.tasks import TaskClient, task_application


@asynccontextmanager
async def start_fastapi(app: FastAPI) -> AsyncIterator:
backdoor.setup(app, port=0)
async with app.router.lifespan_context(app):
yield app

Expand Down

0 comments on commit 44d51f7

Please sign in to comment.