19
19
from apify ._configuration import Configuration
20
20
from apify ._consts import EVENT_LISTENERS_TIMEOUT
21
21
from apify ._crypto import decrypt_input_secrets , load_private_key
22
+ from apify ._models import ActorRun
22
23
from apify ._platform_event_manager import EventManager , LocalEventManager , PlatformEventManager
23
24
from apify ._proxy_configuration import ProxyConfiguration
24
25
from apify ._utils import get_system_info , is_running_in_ipython
@@ -536,7 +537,7 @@ async def start(
536
537
timeout : timedelta | None = None ,
537
538
wait_for_finish : int | None = None ,
538
539
webhooks : list [Webhook ] | None = None ,
539
- ) -> dict :
540
+ ) -> ActorRun :
540
541
"""Run an Actor on the Apify platform.
541
542
542
543
Unlike `Actor.call`, this method just starts the run without waiting for finish.
@@ -565,16 +566,20 @@ async def start(
565
566
566
567
client = self .new_client (token = token ) if token else self ._apify_client
567
568
568
- return await client .actor (actor_id ).start (
569
- run_input = run_input ,
570
- content_type = content_type ,
571
- build = build ,
572
- memory_mbytes = memory_mbytes ,
573
- timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
574
- wait_for_finish = wait_for_finish ,
575
- webhooks = [hook .model_dump (by_alias = True , exclude_unset = True , exclude_defaults = True ) for hook in webhooks ]
576
- if webhooks
577
- else None ,
569
+ return ActorRun .model_validate (
570
+ await client .actor (actor_id ).start (
571
+ run_input = run_input ,
572
+ content_type = content_type ,
573
+ build = build ,
574
+ memory_mbytes = memory_mbytes ,
575
+ timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
576
+ wait_for_finish = wait_for_finish ,
577
+ webhooks = [
578
+ hook .model_dump (by_alias = True , exclude_unset = True , exclude_defaults = True ) for hook in webhooks
579
+ ]
580
+ if webhooks
581
+ else None ,
582
+ )
578
583
)
579
584
580
585
async def abort (
@@ -584,7 +589,7 @@ async def abort(
584
589
token : str | None = None ,
585
590
status_message : str | None = None ,
586
591
gracefully : bool | None = None ,
587
- ) -> dict :
592
+ ) -> ActorRun :
588
593
"""Abort given Actor run on the Apify platform using the current user account.
589
594
590
595
The user account is determined by the `APIFY_TOKEN` environment variable.
@@ -607,7 +612,7 @@ async def abort(
607
612
if status_message :
608
613
await client .run (run_id ).update (status_message = status_message )
609
614
610
- return await client .run (run_id ).abort (gracefully = gracefully )
615
+ return ActorRun . model_validate ( await client .run (run_id ).abort (gracefully = gracefully ) )
611
616
612
617
async def call (
613
618
self ,
@@ -621,7 +626,7 @@ async def call(
621
626
timeout : timedelta | None = None ,
622
627
webhooks : list [Webhook ] | None = None ,
623
628
wait : timedelta | None = None ,
624
- ) -> dict | None :
629
+ ) -> ActorRun | None :
625
630
"""Start an Actor on the Apify Platform and wait for it to finish before returning.
626
631
627
632
It waits indefinitely, unless the wait argument is provided.
@@ -650,16 +655,20 @@ async def call(
650
655
651
656
client = self .new_client (token = token ) if token else self ._apify_client
652
657
653
- return await client .actor (actor_id ).call (
654
- run_input = run_input ,
655
- content_type = content_type ,
656
- build = build ,
657
- memory_mbytes = memory_mbytes ,
658
- timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
659
- webhooks = [hook .model_dump (by_alias = True , exclude_defaults = True , exclude_unset = True ) for hook in webhooks ]
660
- if webhooks
661
- else [],
662
- wait_secs = int (wait .total_seconds ()) if wait is not None else None ,
658
+ return ActorRun .model_validate (
659
+ await client .actor (actor_id ).call (
660
+ run_input = run_input ,
661
+ content_type = content_type ,
662
+ build = build ,
663
+ memory_mbytes = memory_mbytes ,
664
+ timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
665
+ webhooks = [
666
+ hook .model_dump (by_alias = True , exclude_defaults = True , exclude_unset = True ) for hook in webhooks
667
+ ]
668
+ if webhooks
669
+ else [],
670
+ wait_secs = int (wait .total_seconds ()) if wait is not None else None ,
671
+ )
663
672
)
664
673
665
674
async def call_task (
@@ -673,7 +682,7 @@ async def call_task(
673
682
webhooks : list [Webhook ] | None = None ,
674
683
wait : timedelta | None = None ,
675
684
token : str | None = None ,
676
- ) -> dict | None :
685
+ ) -> ActorRun | None :
677
686
"""Start an Actor task on the Apify Platform and wait for it to finish before returning.
678
687
679
688
It waits indefinitely, unless the wait argument is provided.
@@ -705,15 +714,19 @@ async def call_task(
705
714
706
715
client = self .new_client (token = token ) if token else self ._apify_client
707
716
708
- return await client .task (task_id ).call (
709
- task_input = task_input ,
710
- build = build ,
711
- memory_mbytes = memory_mbytes ,
712
- timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
713
- webhooks = [hook .model_dump (by_alias = True , exclude_defaults = True , exclude_unset = True ) for hook in webhooks ]
714
- if webhooks
715
- else [],
716
- wait_secs = int (wait .total_seconds ()) if wait is not None else None ,
717
+ return ActorRun .model_validate (
718
+ await client .task (task_id ).call (
719
+ task_input = task_input ,
720
+ build = build ,
721
+ memory_mbytes = memory_mbytes ,
722
+ timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
723
+ webhooks = [
724
+ hook .model_dump (by_alias = True , exclude_defaults = True , exclude_unset = True ) for hook in webhooks
725
+ ]
726
+ if webhooks
727
+ else [],
728
+ wait_secs = int (wait .total_seconds ()) if wait is not None else None ,
729
+ )
717
730
)
718
731
719
732
async def metamorph (
0 commit comments