File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -784,8 +784,7 @@ def info(self) -> temporalio.activity.Info:
784784 return self ._info
785785
786786 def heartbeat (self , * details : Any ) -> None :
787- info = temporalio .activity .info ()
788- self ._worker ._heartbeat (info .task_token , * details )
787+ self ._worker ._heartbeat (self ._info .task_token , * details )
789788
790789
791790# This has to be defined at the top-level to be picklable for process executors
Original file line number Diff line number Diff line change @@ -1416,3 +1416,30 @@ async def raise_error():
14161416
14171417 finally :
14181418 activity .logger .base_logger .removeHandler (CustomLogHandler ())
1419+
1420+
1421+ async def test_activity_heartbeat_context (client : Client , worker : ExternalWorker ):
1422+ @activity .defn
1423+ async def heartbeat ():
1424+ if activity .info ().attempt == 1 :
1425+ context : activity ._Context = activity ._Context .current ()
1426+
1427+ def heartbeat_task ():
1428+ async def h ():
1429+ if context .heartbeat is not None :
1430+ context .heartbeat ("Some detail" )
1431+
1432+ asyncio .run (h ())
1433+
1434+ thread = threading .Thread (target = heartbeat_task )
1435+ thread .start ()
1436+ thread .join ()
1437+ raise RuntimeError ("oh no!" )
1438+ else :
1439+ assert len (activity .info ().heartbeat_details ) == 1
1440+ return "details: " + activity .info ().heartbeat_details [0 ]
1441+
1442+ result = await _execute_workflow_with_activity (
1443+ client , worker , heartbeat , retry_max_attempts = 2
1444+ )
1445+ assert result .result == "details: Some detail"
You can’t perform that action at this time.
0 commit comments