diff --git a/reginald/models/app.py b/reginald/models/app.py index 9701938e..b64b90c0 100644 --- a/reginald/models/app.py +++ b/reginald/models/app.py @@ -43,8 +43,8 @@ def main(): # set up basic root endpoint @app.get("/") - async def root(): - return "Hello World!" + async def ping(): + return "pong" # set up direct_message endpoint @app.get("/direct_message") diff --git a/reginald/slack_bot/bot.py b/reginald/slack_bot/bot.py index 7594cb8a..978c080a 100644 --- a/reginald/slack_bot/bot.py +++ b/reginald/slack_bot/bot.py @@ -394,6 +394,8 @@ async def _process_request( # if this is a direct message to Reginald... if event_type == "message" and event_subtype is None: await self.react(client, event["channel"], event["ts"]) + # check VM is reachable + await self.ping() model_response = await asyncio.get_running_loop().run_in_executor( None, lambda: requests.get( @@ -405,6 +407,8 @@ async def _process_request( # if @Reginald is mentioned in a channel elif event_type == "app_mention": await self.react(client, event["channel"], event["ts"]) + # check VM is reachable + await self.ping() model_response = await asyncio.get_running_loop().run_in_executor( None, lambda: requests.get( @@ -473,6 +477,16 @@ async def _process_request( else: logging.info("No reply was generated.") + async def ping(self): + pong = await asyncio.get_running_loop().run_in_executor( + None, + lambda: requests.get( + f"{self.api_url}/", + timeout=5, + ), + ) + pong.raise_for_status() + async def react( self, client: SocketModeClient, channel: str, timestamp: str ) -> None: