Spaces:
Build error
Build error
| import time | |
| from fastapi import FastAPI, Request | |
| from openhands.runtime.utils.system_stats import get_system_stats | |
| start_time = time.time() | |
| last_execution_time = start_time | |
| def add_health_endpoints(app: FastAPI): | |
| async def alive(): | |
| return {'status': 'ok'} | |
| async def health() -> str: | |
| return 'OK' | |
| async def get_server_info(): | |
| current_time = time.time() | |
| uptime = current_time - start_time | |
| idle_time = current_time - last_execution_time | |
| response = { | |
| 'uptime': uptime, | |
| 'idle_time': idle_time, | |
| 'resources': get_system_stats(), | |
| } | |
| return response | |
| async def update_last_execution_time(request: Request, call_next): | |
| global last_execution_time | |
| response = await call_next(request) | |
| last_execution_time = time.time() | |
| return response | |