LiKenun commited on
Commit
a08a6f4
·
1 Parent(s): 98a6105

Replace temporary independent health check process with integrated health check endpoint

Browse files
Dockerfile CHANGED
@@ -28,10 +28,5 @@ USER appuser
28
  # Expose a volume mount for logs ― Hugging Face Spaces requires specifically /data.
29
  VOLUME /data
30
 
31
- # Temporary block for the health server fix:
32
- COPY scripts/run.sh ./scripts/
33
- COPY temporary_health_check_server.py ./
34
- CMD ["./scripts/run.sh"]
35
-
36
  # Run the application.
37
- #CMD ["python", "-m", "ctp_slack_bot.app"]
 
28
  # Expose a volume mount for logs ― Hugging Face Spaces requires specifically /data.
29
  VOLUME /data
30
 
 
 
 
 
 
31
  # Run the application.
32
+ CMD ["python", "-m", "ctp_slack_bot.app"]
scripts/run.sh DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
-
3
- parent_path=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)
4
-
5
- cd "${parent_path}/.."
6
-
7
- python -m ctp_slack_bot.app & python "temporary_health_check_server.py"
 
 
 
 
 
 
 
 
src/ctp_slack_bot/app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from asyncio import all_tasks, CancelledError, create_task, current_task, get_running_loop, run
2
  from loguru import logger
3
  from signal import SIGINT, SIGTERM
@@ -6,18 +7,6 @@ from typing import Any, Callable
6
  from ctp_slack_bot.containers import Container
7
  from ctp_slack_bot.core.logging import setup_logging
8
 
9
- async def handle_shutdown_signal() -> None:
10
- logger.info("Received shutdown signal.")
11
- for task in all_tasks():
12
- if task is not current_task() and not task.done():
13
- task.cancel()
14
- logger.trace("Cancelled task {}.", task.get_name())
15
- logger.info("Cancelled all tasks.")
16
-
17
- def create_shutdown_signal_handler() -> Callable[[], None]:
18
- def shutdown_signal_handler() -> None:
19
- create_task(handle_shutdown_signal())
20
- return shutdown_signal_handler
21
 
22
  async def main() -> None:
23
  # Setup logging.
@@ -26,13 +15,36 @@ async def main() -> None:
26
 
27
  # Set up dependency injection container.
28
  container = Container()
29
- container.wire(packages=['ctp_slack_bot'])
30
 
31
  # Kick off services which should be active from the start.
32
  container.content_ingestion_service()
33
  container.question_dispatch_service()
34
  container.schedule_service()
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  # Start the Slack socket mode handler in the background.
37
  socket_mode_handler = await container.socket_mode_handler()
38
  slack_bolt_task = create_task(socket_mode_handler.start_async())
 
1
+ from aiohttp.web import Application as WebApplication, AppRunner as WebAppRunner, Response, TCPSite
2
  from asyncio import all_tasks, CancelledError, create_task, current_task, get_running_loop, run
3
  from loguru import logger
4
  from signal import SIGINT, SIGTERM
 
7
  from ctp_slack_bot.containers import Container
8
  from ctp_slack_bot.core.logging import setup_logging
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  async def main() -> None:
12
  # Setup logging.
 
15
 
16
  # Set up dependency injection container.
17
  container = Container()
18
+ container.wire(packages=["ctp_slack_bot"])
19
 
20
  # Kick off services which should be active from the start.
21
  container.content_ingestion_service()
22
  container.question_dispatch_service()
23
  container.schedule_service()
24
 
25
+ async def health(request):
26
+ return Response(text="lol")
27
+ http_server = WebApplication()
28
+ http_server.router.add_get("/health", health)
29
+ web_app_runner = WebAppRunner(http_server)
30
+ await web_app_runner.setup()
31
+ website = TCPSite(web_app_runner, "0.0.0.0", 8080)
32
+ await website.start()
33
+
34
+ async def handle_shutdown_signal() -> None:
35
+ logger.info("Received shutdown signal.")
36
+ await web_app_runner.cleanup()
37
+ for task in all_tasks():
38
+ if task is not current_task() and not task.done():
39
+ task.cancel()
40
+ logger.trace("Cancelled task {}.", task.get_name())
41
+ logger.info("Cancelled all tasks.")
42
+
43
+ def create_shutdown_signal_handler() -> Callable[[], None]:
44
+ def shutdown_signal_handler() -> None:
45
+ create_task(handle_shutdown_signal())
46
+ return shutdown_signal_handler
47
+
48
  # Start the Slack socket mode handler in the background.
49
  socket_mode_handler = await container.socket_mode_handler()
50
  slack_bolt_task = create_task(socket_mode_handler.start_async())
temporary_health_check_server.py DELETED
@@ -1,11 +0,0 @@
1
- from aiohttp import web
2
-
3
- async def aliveness_handler(request):
4
- return web.Response(text="Server is alive and kicking!")
5
-
6
- app = web.Application()
7
- app.router.add_get('/', aliveness_handler)
8
- app.router.add_get('/health', aliveness_handler)
9
-
10
- if __name__ == "__main__":
11
- web.run_app(app, host='0.0.0.0', port=8080)