Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30ad913

Browse files
committed
Review comments
1 parent 7202c17 commit 30ad913

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/apify/_actor.py

Lines 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 Apifyplatform 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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ async def test_actor_start_remaining_timeout(
1313
make_actor: MakeActorFunction,
1414
run_actor: RunActorFunction,
1515
) -> None:
16+
"""In this test one Actor starts itself again and checks that the timeout is correctly set on the second Actor run.
17+
18+
This timeout should be the remaining time of the first Actor run."""
19+
1620
async def main() -> None:
1721
from datetime import datetime, timezone
1822

1923
async with Actor:
2024
actor_input = (await Actor.get_input()) or {}
2125
if actor_input.get('called_from_another_actor', False) is True:
26+
# If this Actor run was started with specific arguement (the second actor run), return immediately.
2227
return
2328

2429
# Start another run of this actor with timeout set to the time remaining in this actor run
@@ -53,16 +58,19 @@ async def test_actor_call_remaining_timeout(
5358
make_actor: MakeActorFunction,
5459
run_actor: RunActorFunction,
5560
) -> None:
61+
"""In this test one Actor starts itself again and checks that the timeout is correctly set on the second Actor run.
62+
63+
This timeout should be the remaining time of the first Actor run."""
64+
5665
async def main() -> None:
5766
from datetime import datetime, timezone
5867

5968
async with Actor:
6069
actor_input = (await Actor.get_input()) or {}
6170
if actor_input.get('called_from_another_actor', False) is True:
71+
# If this Actor run was started with specific arguement (the second actor run), return immediately.
6272
return
6373

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

0 commit comments

Comments
 (0)