@@ -951,7 +951,7 @@ async def start(
951951 timeout : timedelta | Literal ['inherit' ] | None = None ,
952952 force_permission_level : ActorPermissionLevel | None = None ,
953953 webhooks : list [Webhook ] | None = None ,
954- name : str | None = None ,
954+ run_name : str | None = None ,
955955 abort_with_parent : bool = False ,
956956 ) -> Run :
957957 """Run an Actor on the Apify platform.
@@ -979,21 +979,21 @@ async def start(
979979 webhooks: Optional ad-hoc webhooks (https://docs.apify.com/webhooks/ad-hoc-webhooks) associated with
980980 the Actor run which can be used to receive a notification, e.g. when the Actor finished or failed.
981981 If you already have a webhook set up for the Actor or task, you do not have to add it again here.
982- name : Optional name of the child run, unique within this Actor run. A named run is recorded in the
982+ run_name : Optional name of the child run, unique within this Actor run. A named run is recorded in the
983983 default key-value store, so after a migration or resurrection of this Actor the same call reattaches
984984 to the recorded run. A `SUCCEEDED` run is returned as is, an `ABORTED` or `TIMED-OUT` one is
985985 resurrected, and a new run is started only when nothing is recorded under the name, or the recorded
986986 run `FAILED` or no longer exists. The name is bound to `actor_id` exactly as passed, so reusing it with
987- any other value raises a `ValueError`.
987+ any other value, or for a task, raises a `ValueError`.
988988 abort_with_parent: If true, the child run is gracefully aborted when this Actor run is gracefully
989- aborted. It requires `name `, and the value is recorded under it, replacing the one from an earlier
989+ aborted. It requires `run_name `, and the value is recorded under it, replacing the one from an earlier
990990 call. A hard abort, a timeout or a crash of this Actor run leaves the child running.
991991
992992 Returns:
993993 Info about the started Actor run
994994 """
995- if abort_with_parent and name is None :
996- raise ValueError ('`abort_with_parent` requires `name `, since only named child runs are tracked.' )
995+ if abort_with_parent and run_name is None :
996+ raise ValueError ('`abort_with_parent` requires `run_name `, since only named child runs are tracked.' )
997997
998998 client = self .new_client (token = token ) if token else self .apify_client
999999
@@ -1020,11 +1020,11 @@ async def start(
10201020 webhooks = to_client_representations (webhooks ),
10211021 )
10221022
1023- if name is None :
1023+ if run_name is None :
10241024 return await start_run ()
10251025
10261026 run , _ = await self ._find_or_start_child_run (
1027- name ,
1027+ run_name ,
10281028 actor_id = actor_id ,
10291029 client = client ,
10301030 start_run = start_run ,
@@ -1091,7 +1091,7 @@ async def call(
10911091 webhooks : list [Webhook ] | None = None ,
10921092 wait : timedelta | None = None ,
10931093 logger : logging .Logger | Literal ['default' ] | None = 'default' ,
1094- name : str | None = None ,
1094+ run_name : str | None = None ,
10951095 abort_with_parent : bool = False ,
10961096 ) -> Run :
10971097 """Start an Actor on the Apify Platform and wait for it to finish before returning.
@@ -1122,21 +1122,21 @@ async def call(
11221122 logger: Logger used to redirect logs from the Actor run. Using "default" literal means that a predefined
11231123 default logger will be used. Setting `None` will disable any log propagation. Passing custom logger
11241124 will redirect logs to the provided logger.
1125- name : Optional name of the child run, unique within this Actor run. A named run is recorded in the
1125+ run_name : Optional name of the child run, unique within this Actor run. A named run is recorded in the
11261126 default key-value store, so after a migration or resurrection of this Actor the same call reattaches
11271127 to the recorded run. A `SUCCEEDED` run is returned as is, an `ABORTED` or `TIMED-OUT` one is
11281128 resurrected, and a new run is started only when nothing is recorded under the name, or the recorded
11291129 run `FAILED` or no longer exists. The name is bound to `actor_id` exactly as passed, so reusing it with
1130- any other value raises a `ValueError`.
1130+ any other value, or for a task, raises a `ValueError`.
11311131 abort_with_parent: If true, the child run is gracefully aborted when this Actor run is gracefully
1132- aborted. It requires `name `, and the value is recorded under it, replacing the one from an earlier
1132+ aborted. It requires `run_name `, and the value is recorded under it, replacing the one from an earlier
11331133 call. A hard abort, a timeout or a crash of this Actor run leaves the child running.
11341134
11351135 Returns:
11361136 Info about the started Actor run.
11371137 """
1138- if abort_with_parent and name is None :
1139- raise ValueError ('`abort_with_parent` requires `name `, since only named child runs are tracked.' )
1138+ if abort_with_parent and run_name is None :
1139+ raise ValueError ('`abort_with_parent` requires `run_name `, since only named child runs are tracked.' )
11401140
11411141 client = self .new_client (token = token ) if token else self .apify_client
11421142
@@ -1151,7 +1151,7 @@ async def call(
11511151
11521152 actor_client = client .actor (actor_id )
11531153
1154- if name is None :
1154+ if run_name is None :
11551155 run = await actor_client .call (
11561156 run_input = run_input ,
11571157 content_type = content_type ,
@@ -1167,7 +1167,7 @@ async def call(
11671167 )
11681168 else :
11691169 started_run , is_new = await self ._find_or_start_child_run (
1170- name ,
1170+ run_name ,
11711171 actor_id = actor_id ,
11721172 client = client ,
11731173 start_run = partial (
@@ -1203,7 +1203,8 @@ async def _find_or_start_child_run(
12031203 self ,
12041204 name : str ,
12051205 * ,
1206- actor_id : str ,
1206+ actor_id : str | None = None ,
1207+ task_id : str | None = None ,
12071208 client : ApifyClientAsync ,
12081209 start_run : Callable [[], Awaitable [Run ]],
12091210 build : str | None ,
@@ -1216,6 +1217,7 @@ async def _find_or_start_child_run(
12161217 return await self ._child_run_registry .find_or_start (
12171218 name ,
12181219 actor_id = actor_id ,
1220+ task_id = task_id ,
12191221 client = client ,
12201222 start_run = start_run ,
12211223 resurrect_run = lambda run_client : run_client .resurrect (
@@ -1261,9 +1263,9 @@ async def _wait_for_child_run(
12611263 async def child_runs (self ) -> dict [str , ChildRunInfo ]:
12621264 """Get the named child runs of this Actor run, with their current state.
12631265
1264- Every run started by `Actor.start` or `Actor.call ` with a `name ` is included, even one started before a
1265- migration or resurrection of this Actor run. Runs started without a `name ` are not tracked. Each run is fetched
1266- from the API when this method is called, so the result is a snapshot.
1266+ Every run started by `Actor.start`, `Actor.call` or `Actor.call_task ` with a `run_name ` is included, even one
1267+ started before a migration or resurrection of this Actor run. Runs started without a `run_name ` are not
1268+ tracked. Each run is fetched from the API when this method is called, so the result is a snapshot.
12671269
12681270 Returns:
12691271 The child runs by name.
@@ -1283,6 +1285,7 @@ async def call_task(
12831285 webhooks : list [Webhook ] | None = None ,
12841286 wait : timedelta | None = None ,
12851287 token : str | None = None ,
1288+ run_name : str | None = None ,
12861289 ) -> Run :
12871290 """Start an Actor task on the Apify Platform and wait for it to finish before returning.
12881291
@@ -1308,6 +1311,12 @@ async def call_task(
13081311 be used to receive a notification, e.g. when the Actor finished or failed. If you already have
13091312 a webhook set up for the Actor, you do not have to add it again here.
13101313 wait: The maximum time the server waits for the run to finish. If not provided, waits indefinitely.
1314+ run_name: Optional name of the child run, unique within this Actor run. A named run is recorded in the
1315+ default key-value store, so after a migration or resurrection of this Actor the same call reattaches
1316+ to the recorded run. A `SUCCEEDED` run is returned as is, an `ABORTED` or `TIMED-OUT` one is
1317+ resurrected, and a new run is started only when nothing is recorded under the name, or the recorded
1318+ run `FAILED` or no longer exists. The name is bound to `task_id` exactly as passed, so reusing it with
1319+ any other value, or for an Actor, raises a `ValueError`.
13111320
13121321 Returns:
13131322 Info about the started Actor run.
@@ -1324,15 +1333,41 @@ async def call_task(
13241333 raise ValueError (f'Invalid timeout { timeout !r} : expected `None`, `"inherit"`, or a `timedelta`.' )
13251334
13261335 task_client = client .task (task_id )
1327- run = await task_client .call (
1328- task_input = task_input ,
1329- build = build ,
1330- restart_on_error = restart_on_error ,
1331- memory_mbytes = memory_mbytes ,
1332- run_timeout = task_call_timeout ,
1333- webhooks = to_client_representations (webhooks ),
1334- wait_duration = wait ,
1335- )
1336+
1337+ if run_name is None :
1338+ run = await task_client .call (
1339+ task_input = task_input ,
1340+ build = build ,
1341+ restart_on_error = restart_on_error ,
1342+ memory_mbytes = memory_mbytes ,
1343+ run_timeout = task_call_timeout ,
1344+ webhooks = to_client_representations (webhooks ),
1345+ wait_duration = wait ,
1346+ )
1347+ else :
1348+ started_run , _ = await self ._find_or_start_child_run (
1349+ run_name ,
1350+ task_id = task_id ,
1351+ client = client ,
1352+ start_run = partial (
1353+ task_client .start ,
1354+ task_input = task_input ,
1355+ build = build ,
1356+ restart_on_error = restart_on_error ,
1357+ memory_mbytes = memory_mbytes ,
1358+ run_timeout = task_call_timeout ,
1359+ webhooks = to_client_representations (webhooks ),
1360+ ),
1361+ build = build ,
1362+ max_total_charge_usd = None ,
1363+ restart_on_error = restart_on_error ,
1364+ memory_mbytes = memory_mbytes ,
1365+ run_timeout = task_call_timeout ,
1366+ abort_with_parent = False ,
1367+ )
1368+ run = await self ._wait_for_child_run (
1369+ client .run (started_run .id ), started_run , wait = wait , logger = None , from_start = False
1370+ )
13361371
13371372 if run is None :
13381373 raise RuntimeError (f'Failed to call Task with ID "{ task_id } ".' )
0 commit comments