@@ -21,29 +21,26 @@ async def main() -> None:
2121 if actor_input .get ('called_from_another_actor' , False ) is True :
2222 return
2323
24- await asyncio .sleep (1 )
2524 # Start another run of this actor with timeout set to the time remaining in this actor run
26- other_run_data = await Actor .start (
25+ other_run_data = await Actor .call (
2726 actor_id = Actor .configuration .actor_id or '' ,
2827 run_input = {'called_from_another_actor' : True },
2928 timeout = 'RemainingTime' ,
3029 )
31-
32- # To make sure that the actor is started
33- await asyncio .sleep (5 )
34-
35- assert Actor .configuration .timeout_at is not None
36- assert Actor .configuration .started_at is not None
3730 assert other_run_data is not None
38- assert other_run_data .options is not None
31+ try :
32+ # To make sure that the actor is started
33+ await asyncio .sleep (5 )
34+ assert other_run_data .options is not None
35+ assert Actor .configuration .timeout_at is not None
36+ assert Actor .configuration .started_at is not None
3937
40- remaining_time_after_actor_start = Actor .configuration .timeout_at - datetime .now (tz = timezone .utc )
38+ remaining_time_after_actor_start = Actor .configuration .timeout_at - datetime .now (tz = timezone .utc )
4139
42- try :
4340 assert other_run_data .options .timeout > remaining_time_after_actor_start
4441 assert other_run_data .options .timeout < Actor .configuration .timeout_at - Actor .configuration .started_at
4542 finally :
46- # Abort the other actor run after asserting the timeouts
43+ # Make sure the other actor run is aborted
4744 await Actor .apify_client .run (other_run_data .id ).abort ()
4845
4946 actor = await make_actor (label = 'remaining-timeout' , main_func = main )
@@ -65,28 +62,29 @@ async def main() -> None:
6562 return
6663
6764 await asyncio .sleep (1 )
65+
6866 # Start another run of this actor with timeout set to the time remaining in this actor run
6967 other_run_data = await Actor .call (
7068 actor_id = Actor .configuration .actor_id or '' ,
7169 run_input = {'called_from_another_actor' : True },
7270 timeout = 'RemainingTime' ,
7371 )
7472
75- # To make sure that the actor is started
76- await asyncio .sleep (5 )
77-
78- assert Actor .configuration .timeout_at is not None
79- assert Actor .configuration .started_at is not None
8073 assert other_run_data is not None
81- assert other_run_data .options is not None
74+ try :
75+ # To make sure that the actor is started
76+ await asyncio .sleep (5 )
8277
83- remaining_time_after_actor_start = Actor .configuration .timeout_at - datetime .now (tz = timezone .utc )
78+ assert other_run_data .options is not None
79+ assert Actor .configuration .timeout_at is not None
80+ assert Actor .configuration .started_at is not None
81+
82+ remaining_time_after_actor_start = Actor .configuration .timeout_at - datetime .now (tz = timezone .utc )
8483
85- try :
8684 assert other_run_data .options .timeout > remaining_time_after_actor_start
8785 assert other_run_data .options .timeout < Actor .configuration .timeout_at - Actor .configuration .started_at
8886 finally :
89- # Abort the other actor run after asserting the timeouts
87+ # Make sure the other actor run is aborted
9088 await Actor .apify_client .run (other_run_data .id ).abort ()
9189
9290 actor = await make_actor (label = 'remaining-timeout' , main_func = main )
0 commit comments