Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05eed5f

Browse filesBrowse files
committed
Review comments
1 parent 7202c17 commit 05eed5f
Copy full SHA for 05eed5f

File tree

Expand file treeCollapse file tree

2 files changed

+29
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-15
lines changed

‎src/apify/_actor.py

Copy file name to clipboardExpand all lines: src/apify/_actor.py
+15-13Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,8 @@ async def start(
711711
memory_mbytes: Memory limit for the run, in megabytes. By default, the run uses a memory limit specified
712712
in the default run configuration for the Actor.
713713
timeout: Optional timeout for the run, in seconds. By default, the run uses timeout specified in
714-
the default run configuration for the Actor. Using `RemainingTime` will set timeout of the other actor
715-
to the time remaining from this actor timeout.
714+
the default run configuration for the Actor. Using `RemainingTime` will set timeout of the other Actor
715+
to the time remaining from this Actor timeout.
716716
wait_for_finish: The maximum number of seconds the server waits for the run to finish. By default,
717717
it is 0, the maximum value is 300.
718718
webhooks: Optional ad-hoc webhooks (https://docs.apify.com/webhooks/ad-hoc-webhooks) associated with
@@ -740,9 +740,7 @@ async def start(
740740
elif isinstance(timeout, timedelta):
741741
actor_start_timeout = timeout
742742
else:
743-
raise ValueError(
744-
f'Invalid timeout {timeout!r}: expected `None`, `"RemainingTime"`, or a `timedelta`.'
745-
)
743+
raise ValueError(f'Invalid timeout {timeout!r}: expected `None`, `"RemainingTime"`, or a `timedelta`.')
746744

747745
api_result = await client.actor(actor_id).start(
748746
run_input=run_input,
@@ -761,7 +759,11 @@ def _get_remaining_time(self) -> timedelta | None:
761759
if self.is_at_home() and self.configuration.timeout_at:
762760
return self.configuration.timeout_at - datetime.now(tz=timezone.utc)
763761

764-
self.log.warning('Using `RemainingTime` argument for timeout outside of the Apify platform. Returning `None`')
762+
self.log.warning(
763+
'Returning `None` instead of remaining time. Using `RemainingTime` argument is only possible when the Actor'
764+
' is running on the Apify platform and when the timeout for the Actor run is set. '
765+
f'{self.is_at_home()=}, {self.configuration.timeout_at=}'
766+
)
765767
return None
766768

767769
async def abort(
@@ -825,8 +827,8 @@ async def call(
825827
memory_mbytes: Memory limit for the run, in megabytes. By default, the run uses a memory limit specified
826828
in the default run configuration for the Actor.
827829
timeout: Optional timeout for the run, in seconds. By default, the run uses timeout specified in
828-
the default run configuration for the Actor. Using `RemainingTime` will set timeout of the other actor
829-
to the time remaining from this actor timeout.
830+
the default run configuration for the Actor. Using `RemainingTime` will set timeout of the other Actor
831+
to the time remaining from this Actor timeout.
830832
webhooks: Optional webhooks (https://docs.apify.com/webhooks) associated with the Actor run, which can
831833
be used to receive a notification, e.g. when the Actor finished or failed. If you already have
832834
a webhook set up for the Actor, you do not have to add it again here.
@@ -849,12 +851,12 @@ async def call(
849851

850852
if timeout == 'RemainingTime':
851853
actor_call_timeout = self._get_remaining_time()
852-
elif isinstance(timeout, str):
853-
raise ValueError(
854-
f'`timeout` can be `None`, `RemainingTime` literal or `timedelta` instance, but is {timeout=}'
855-
)
856-
else:
854+
elif timeout is None:
855+
actor_call_timeout = None
856+
elif isinstance(timeout, timedelta):
857857
actor_call_timeout = timeout
858+
else:
859+
raise ValueError(f'Invalid timeout {timeout!r}: expected `None`, `"RemainingTime"`, or a `timedelta`.')
858860

859861
api_result = await client.actor(actor_id).call(
860862
run_input=run_input,

‎tests/integration/test_actor_call_timeouts.py

Copy file name to clipboardExpand all lines: tests/integration/test_actor_call_timeouts.py
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ async def test_actor_start_remaining_timeout(
1313
make_actor: MakeActorFunction,
1414
run_actor: RunActorFunction,
1515
) -> None:
16+
"""Test that correct timeout is set when using `RemainingTime` value for the `timeout` argument.
17+
18+
In this test, one Actor starts itself again and checks that the timeout is correctly set on the second Actor run.
19+
Timeout should be the remaining time of the first Actor run calculated at the moment of the other Actor start."""
20+
1621
async def main() -> None:
1722
from datetime import datetime, timezone
1823

1924
async with Actor:
2025
actor_input = (await Actor.get_input()) or {}
2126
if actor_input.get('called_from_another_actor', False) is True:
27+
# If this Actor run was started with a specific argument (the second Actor run), return immediately.
28+
# Asserts checking the timeout are in the first Actor run.
2229
return
2330

2431
# Start another run of this actor with timeout set to the time remaining in this actor run
@@ -53,16 +60,21 @@ async def test_actor_call_remaining_timeout(
5360
make_actor: MakeActorFunction,
5461
run_actor: RunActorFunction,
5562
) -> None:
63+
"""Test that correct timeout is set when using `RemainingTime` value for the `timeout` argument.
64+
65+
In this test, one Actor starts itself again and checks that the timeout is correctly set on the second Actor run.
66+
Timeout should be the remaining time of the first Actor run calculated at the moment of the other Actor call."""
67+
5668
async def main() -> None:
5769
from datetime import datetime, timezone
5870

5971
async with Actor:
6072
actor_input = (await Actor.get_input()) or {}
6173
if actor_input.get('called_from_another_actor', False) is True:
74+
# If this Actor run was started with a specific argument (the second Actor run), return immediately.
75+
# Asserts checking the timeout are in the first Actor run.
6276
return
6377

64-
await asyncio.sleep(1)
65-
6678
# Start another run of this actor with timeout set to the time remaining in this actor run
6779
other_run_data = await Actor.call(
6880
actor_id=Actor.configuration.actor_id or '',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.