1010import inspect
1111import json
1212import re
13- import typing
1413import uuid
1514import warnings
1615from abc import ABC , abstractmethod
@@ -1391,119 +1390,95 @@ async def count_activities(
13911390 # Issues a workflowservice CountActivityExecutions call
13921391 raise NotImplementedError
13931392
1394- @typing .overload
13951393 def get_activity_handle (
13961394 self ,
13971395 * ,
13981396 activity_id : str ,
13991397 run_id : Optional [str ] = None ,
14001398 ) -> ActivityHandle [Any ]:
1401- raise NotImplementedError
1402-
1403- @typing .overload
1404- def get_activity_handle (
1405- self ,
1406- * ,
1407- activity_id : str ,
1408- workflow_id : str ,
1409- run_id : Optional [str ],
1410- ) -> WorkflowActivityHandle :
1411- raise NotImplementedError
1399+ """Get a handle to an existing activity, as the caller of that activity.
14121400
1413- @typing .overload
1414- def get_activity_handle (
1415- self ,
1416- * ,
1417- task_token : bytes ,
1418- ) -> WorkflowActivityHandle :
1419- raise NotImplementedError
1420-
1421- def get_activity_handle (
1422- self ,
1423- * ,
1424- activity_id : Optional [str ] = None ,
1425- workflow_id : Optional [str ] = None ,
1426- run_id : Optional [str ] = None ,
1427- task_token : Optional [bytes ] = None ,
1428- ) -> Union [ActivityHandle [Any ], WorkflowActivityHandle ]:
1429- """Get a handle to an existing activity.
1401+ To get a handle to an activity execution that you control for manual completion and
1402+ heartbeating, see :py:meth:`Client.get_async_activity_handle`.
14301403
14311404 Args:
14321405 activity_id: The activity ID.
1433- workflow_id: The workflow ID if the activity was started from a workflow.
1434- run_id: The run ID. If not provided, targets the latest run.
1435- task_token: Optional task token for the activity if the activity was
1436- started from a workflow. Cannot be set if any of the id parameters
1437- are set.
1406+ run_id: The run ID. If not provided, targets the
1407+ latest run.
14381408
14391409 Returns:
14401410 A handle to the activity.
14411411 """
14421412 raise NotImplementedError
14431413
1444- # Deprecated: get_activity_handle has an equivalent override
14451414 @overload
1446- def get_workflow_activity_handle (
1415+ def get_async_activity_handle (
1416+ self , * , activity_id : str , run_id : Optional [str ]
1417+ ) -> AsyncActivityHandle :
1418+ pass
1419+
1420+ @overload
1421+ def get_async_activity_handle (
14471422 self , * , workflow_id : str , run_id : Optional [str ], activity_id : str
1448- ) -> WorkflowActivityHandle :
1423+ ) -> AsyncActivityHandle :
14491424 pass
14501425
1451- # Deprecated: get_activity_handle has an equivalent override
14521426 @overload
1453- def get_workflow_activity_handle (
1454- self , * , task_token : bytes
1455- ) -> WorkflowActivityHandle :
1427+ def get_async_activity_handle (self , * , task_token : bytes ) -> AsyncActivityHandle :
14561428 pass
14571429
1458- def get_workflow_activity_handle (
1430+ def get_async_activity_handle (
14591431 self ,
14601432 * ,
14611433 workflow_id : Optional [str ] = None ,
14621434 run_id : Optional [str ] = None ,
14631435 activity_id : Optional [str ] = None ,
14641436 task_token : Optional [bytes ] = None ,
1465- ) -> WorkflowActivityHandle :
1466- """Get a handle to an activity started by a workflow .
1437+ ) -> AsyncActivityHandle :
1438+ """Get a handle to an activity execution that you control, for manual completion and heartbeating .
14671439
1468- .. warning::
1469- DEPRECATED: This method is deprecated.
1470- Use :py:meth:`Client.get_activity_handle` instead.
1440+ To get a handle to a standalone activity execution as the caller of that activity, see
1441+ :py:meth:`Client.get_activity_handle`.
1442+
1443+ This function may be used to get a handle to a standalone activity started by a client, or
1444+ an activity started by a workflow.
1445+
1446+ To get a handle to an activity started by a workflow, use one of the following two calls:
1447+ - Supply ``workflow_id``, ``run_id``, and ``activity_id``
1448+ - Supply the activity ``task_token`` alone
1449+
1450+ To get a handle to a standalone activity started by a client, supply ``activity_id`` and
1451+ ``run_id``
14711452
1472- Either the workflow_id, run_id, and activity_id can be provided, or a
1473- singular task_token can be provided.
14741453
14751454 Args:
1476- workflow_id: Workflow ID for the activity. Cannot be set if
1477- task_token is set.
1478- run_id: Run ID for the activity. Cannot be set if task_token is set.
1479- activity_id: ID for the activity. Cannot be set if task_token is
1480- set.
1481- task_token: Task token for the activity. Cannot be set if any of the
1482- id parameters are set.
1455+ workflow_id: Workflow ID for the activity.
1456+ run_id: Run ID for the activity. Cannot be
1457+ set if task_token is set.
1458+ activity_id: ID for the activity.
1459+ activity_id: ID for the activity.
1460+ task_token: Task token for the activity.
14831461
14841462 Returns:
1485- A handle that can be used for completion or heartbeat .
1463+ A handle that can be used for completion or heartbeating .
14861464 """
14871465 if task_token is not None :
14881466 if workflow_id is not None or run_id is not None or activity_id is not None :
14891467 raise ValueError ("Task token cannot be present with other IDs" )
1490- return WorkflowActivityHandle (self , task_token )
1468+ return AsyncActivityHandle (self , task_token )
14911469 elif workflow_id is not None :
14921470 if activity_id is None :
14931471 raise ValueError (
14941472 "Workflow ID, run ID, and activity ID must all be given together"
14951473 )
1496- return WorkflowActivityHandle (
1474+ return AsyncActivityHandle (
14971475 self ,
14981476 AsyncActivityIDReference (
14991477 workflow_id = workflow_id , run_id = run_id , activity_id = activity_id
15001478 ),
15011479 )
15021480 raise ValueError ("Task token or workflow/run/activity ID must be present" )
15031481
1504- # Deprecated alias
1505- get_async_activity_handle = get_workflow_activity_handle
1506-
15071482 async def create_schedule (
15081483 self ,
15091484 id : str ,
@@ -3078,12 +3053,19 @@ class ActivityIDReference:
30783053AsyncActivityIDReference = ActivityIDReference
30793054
30803055
3081- class _BaseActivityHandle (WithSerializationContext ):
3082- """Handle representing an activity."""
3056+ class AsyncActivityHandle (WithSerializationContext ):
3057+ """Handle representing an external activity for completion and heartbeat ."""
30833058
3084- _client : Client
3085- _id_or_token : Union [ActivityIDReference , bytes ]
3086- _data_converter_override : Optional [DataConverter ]
3059+ def __init__ (
3060+ self ,
3061+ client : Client ,
3062+ id_or_token : Union [AsyncActivityIDReference , bytes ],
3063+ data_converter_override : Optional [DataConverter ] = None ,
3064+ ) -> None :
3065+ """Create an async activity handle."""
3066+ self ._client = client
3067+ self ._id_or_token = id_or_token
3068+ self ._data_converter_override = data_converter_override
30873069
30883070 async def heartbeat (
30893071 self ,
@@ -3291,21 +3273,6 @@ async def reset(
32913273 timeout = rpc_timeout ,
32923274 )
32933275
3294-
3295- class WorkflowActivityHandle (_BaseActivityHandle ):
3296- """Handle representing an activity started by a workflow."""
3297-
3298- def __init__ (
3299- self ,
3300- client : Client ,
3301- id_or_token : Union [ActivityIDReference , bytes ],
3302- data_converter_override : Optional [DataConverter ] = None ,
3303- ) -> None :
3304- """Create an async activity handle."""
3305- self ._client = client
3306- self ._id_or_token = id_or_token
3307- self ._data_converter_override = data_converter_override
3308-
33093276 def with_context (self , context : SerializationContext ) -> Self :
33103277 """Create a new AsyncActivityHandle with a different serialization context.
33113278
@@ -3330,14 +3297,10 @@ def with_context(self, context: SerializationContext) -> Self:
33303297 )
33313298
33323299
3333- # Deprecated alias
3334- AsyncActivityHandle = WorkflowActivityHandle
3335-
3336-
33373300# TODO: in the future when messages can be sent to activities, we will want the activity handle to
33383301# be generic in the activity type in addition to the return type (as WorkflowHandle), to support
33393302# static type inference for signal/query/update.
3340- class ActivityHandle (Generic [ReturnType ], _BaseActivityHandle ):
3303+ class ActivityHandle (Generic [ReturnType ]):
33413304 """Handle representing a standalone activity execution."""
33423305
33433306 def __init__ (
0 commit comments