from socket import gethostname from app.core.constants import ActorValue from app.core.database import SessionLocal from app.modules.observability.constants import HeartbeatComponent from app.modules.observability.service import ObservabilityService from app.tasks.app import celery_app from app.tasks.constants import TASK_RECORD_WORKER_HEARTBEAT @celery_app.task(name=TASK_RECORD_WORKER_HEARTBEAT) def record_worker_heartbeat_task( actor: str = ActorValue.WORKER, ) -> dict: """Record liveness from the Celery process that actually executes the task.""" db = SessionLocal() try: return ObservabilityService(db).record_heartbeat( component=HeartbeatComponent.WORKER, instance_id=gethostname(), actor=actor, ) finally: db.close()