Skip to content

Commit

Permalink
apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketmaurya committed Sep 18, 2024
1 parent 2655067 commit 4b39bac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/litserve/callbacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class EventTypes:
AFTER_ENCODE_RESPONSE = "on_after_encode_response"
BEFORE_PREDICT = "on_before_predict"
AFTER_PREDICT = "on_after_predict"
BEFORE_SERVER_REGISTER = "on_before_server_register"
AFTER_SERVER_REGISTER = "on_after_server_register"
ON_SERVER_START = "on_server_start"
ON_SERVER_END = "on_serve_end"


class Callback(ABC):
Expand Down Expand Up @@ -45,11 +45,11 @@ def on_before_predict(self, *args, **kwargs):
def on_after_predict(self, *args, **kwargs):
"""Called after prediction is completed."""

def on_before_server_register(self, *args, **kwargs):
"""Called before LitServer endpoint setup is started."""
def on_server_start(self, *args, **kwargs):
"""Called before server starts."""

def on_after_server_register(self, *args, **kwargs):
"""Called after LitServer endpoint setup is completed."""
def on_server_end(self, *args, **kwargs):
"""Called when server terminates."""


class CallbackRunner:
Expand Down
5 changes: 2 additions & 3 deletions src/litserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async def lifespan(self, app: FastAPI):

yield

self._callback_runner.trigger_event(EventTypes.ON_SERVER_END, litserver=self)
task.cancel()
logger.debug("Shutting down response queue to buffer task")

Expand Down Expand Up @@ -294,7 +295,7 @@ async def data_streamer(self, q: deque, data_available: asyncio.Event, send_stat

def register_endpoints(self):
"""Register endpoint routes for the FastAPI app and setup middlewares."""
self._callback_runner.trigger_event(EventTypes.BEFORE_SERVER_REGISTER, litserver=self)
self._callback_runner.trigger_event(EventTypes.ON_SERVER_START, litserver=self)
workers_ready = False

@self.app.get("/", dependencies=[Depends(self.setup_auth())])
Expand Down Expand Up @@ -380,8 +381,6 @@ async def stream_predict(request: self.request_type) -> self.response_type:
elif callable(middleware):
self.app.add_middleware(middleware)

self._callback_runner.trigger_event(EventTypes.AFTER_SERVER_REGISTER, litserver=self)

@staticmethod
def generate_client_file():
src_path = os.path.join(os.path.dirname(__file__), "python_client.py")
Expand Down

0 comments on commit 4b39bac

Please sign in to comment.