I have an activity defined like
@activity.defn
def some_activity(self, request) -> response:
with register_heartbeat(activity.info()):
time.sleep(50)
return response
where register_heartbeat looks like
@contextmanager
def register_heartbeat(heartbeater: TemporalHeartbeater, task_id: ActivityInfo) -> Iterator[None]:
try:
heartbeater.register(task_id)
yield
finally:
heartbeater.unregister(task_id)
the TemporalHeartbeater class is responsible for registering, and unregistering tasks and heartbeats on their behalf in the main thread. the code for the heartbeat loop is below
async def heartbeat_loop(self, heartbeat_interval: timedelta = timedelta(seconds=10)) -> None:
"""Background task that sends heartbeats every 10 seconds."""
while True:
for task_id in self._registered:
handle = self._client.get_async_activity_handle(task_token=task_id.task_token)
await handle.heartbeat()
await asyncio.sleep(heartbeat_interval.total_seconds())
With this code, I can see the last_heartbeat getting updated every 10 seconds on the temporal ui. Despite this, the activity still times out after 30 seconds (my set heartbeat timeout)
However, when I make the activity async, the code executes without getting the heartbeat timeout
Is there a function other than get_async_activity_handle, I’m supposed to be using to heartbeat on behalf of a synchronous activity? Any help would be appreciated!