Skip to content

Commit b938289

Browse files
committed
feat: list task child runs in Actor.child_runs()
1 parent ccf93c5 commit b938289

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎src/apify/_actor.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,9 +1233,9 @@ async def _wait_for_child_run(
12331233
async def child_runs(self) -> dict[str, ChildRunInfo]:
12341234
"""Get the named child runs of this Actor run, with their current state.
12351235
1236-
Every run started by `Actor.start` or `Actor.call` with a `name` is included, even one started before a
1237-
migration or resurrection of this Actor run. Runs started without a `name` are not tracked. Each run is fetched
1238-
from the API when this method is called, so the result is a snapshot.
1236+
Every run started by `Actor.start`, `Actor.call` or `Actor.call_task` with a `run_name` is included, even one
1237+
started before a migration or resurrection of this Actor run. Runs started without a `run_name` are not
1238+
tracked. Each run is fetched from the API when this method is called, so the result is a snapshot.
12391239
12401240
Returns:
12411241
The child runs by name.

‎src/apify/_child_runs.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ def _describe_started_from(actor_id: str | None, task_id: str | None) -> str:
6464
class ChildRunInfo:
6565
"""A named child run of this Actor run, as returned by `Actor.child_runs`."""
6666

67-
actor_id: str
68-
"""The Actor ID or name the child was started with, as the caller passed it."""
67+
actor_id: str | None
68+
"""The Actor ID or name the child was started with, as the caller passed it, or `None` for a task run."""
69+
70+
task_id: str | None
71+
"""The task ID or name the child was started with, as the caller passed it, or `None` for an Actor run."""
6972

7073
run_id: str
7174
"""ID of the current run under this name."""
@@ -170,6 +173,7 @@ async def list_runs(self, client: ApifyClientAsync) -> dict[str, ChildRunInfo]:
170173
return {
171174
name: ChildRunInfo(
172175
actor_id=record.actor_id,
176+
task_id=record.task_id,
173177
run_id=record.run_id,
174178
run=run,
175179
previous_run_ids=list(record.previous_run_ids),

‎tests/unit/actor/test_actor_child_runs.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,17 +457,19 @@ async def get_run(run_client: Any, *_args: Any, **_kwargs: Any) -> Run | None:
457457
CHILD_RUNS_KEY,
458458
{
459459
'scrape-eu': {'actorId': 'some-actor', 'runId': 'eu-run', 'previousRunIds': ['failed-run']},
460-
'scrape-us': {'actorId': 'other-actor', 'runId': 'us-run', 'previousRunIds': []},
460+
'scrape-us': {'taskId': 'some-task', 'runId': 'us-run', 'previousRunIds': []},
461461
},
462462
)
463463
child_runs = await Actor.child_runs()
464464

465465
assert child_runs.keys() == {'scrape-eu', 'scrape-us'}
466466
assert child_runs['scrape-eu'].actor_id == 'some-actor'
467+
assert child_runs['scrape-eu'].task_id is None
467468
assert child_runs['scrape-eu'].run_id == 'eu-run'
468469
assert child_runs['scrape-eu'].run == runs['eu-run']
469470
assert child_runs['scrape-eu'].previous_run_ids == ['failed-run']
470-
assert child_runs['scrape-us'].actor_id == 'other-actor'
471+
assert child_runs['scrape-us'].actor_id is None
472+
assert child_runs['scrape-us'].task_id == 'some-task'
471473
assert child_runs['scrape-us'].run is None
472474

473475

@@ -479,7 +481,7 @@ async def test_child_runs_includes_run_started_in_this_attempt(
479481
apify_client_async_patcher.patch('run', 'get', return_value=make_run('new-run', 'RUNNING'))
480482

481483
async with Actor:
482-
await Actor.start('some-actor', name='scrape-eu')
484+
await Actor.start('some-actor', run_name='scrape-eu')
483485
child_runs = await Actor.child_runs()
484486

485487
assert child_runs['scrape-eu'].run_id == 'new-run'

0 commit comments

Comments
 (0)