11
11
from typing_extensions import Self
12
12
13
13
from apify_client import ApifyClientAsync
14
- from apify_shared .consts import ActorEnvVars , ActorExitCodes , ApifyEnvVars , WebhookEventType
14
+ from apify_shared .consts import ActorEnvVars , ActorExitCodes , ApifyEnvVars
15
15
from apify_shared .utils import ignore_docs , maybe_extract_enum_member_value
16
16
from crawlee import service_container
17
17
from crawlee .events ._types import Event , EventPersistStateData
32
32
33
33
from crawlee .proxy_configuration import _NewUrlFunction
34
34
35
+ from apify ._models import Webhook
36
+
35
37
36
38
MainReturnType = TypeVar ('MainReturnType' )
37
39
@@ -533,7 +535,7 @@ async def start(
533
535
memory_mbytes : int | None = None ,
534
536
timeout : timedelta | None = None ,
535
537
wait_for_finish : int | None = None ,
536
- webhooks : list [dict ] | None = None ,
538
+ webhooks : list [Webhook ] | None = None ,
537
539
) -> dict :
538
540
"""Run an Actor on the Apify platform.
539
541
@@ -555,10 +557,6 @@ async def start(
555
557
webhooks: Optional ad-hoc webhooks (https://docs.apify.com/webhooks/ad-hoc-webhooks) associated with
556
558
the Actor run which can be used to receive a notification, e.g. when the Actor finished or failed.
557
559
If you already have a webhook set up for the Actor or task, you do not have to add it again here.
558
- Each webhook is represented by a dictionary containing these items:
559
- * `event_types`: list of `WebhookEventType` values which trigger the webhook
560
- * `request_url`: URL to which to send the webhook HTTP request
561
- * `payload_template` (optional): Optional template for the request payload
562
560
563
561
Returns:
564
562
Info about the started Actor run
@@ -574,7 +572,9 @@ async def start(
574
572
memory_mbytes = memory_mbytes ,
575
573
timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
576
574
wait_for_finish = wait_for_finish ,
577
- webhooks = webhooks ,
575
+ webhooks = [hook .model_dump (by_alias = True , exclude_unset = True , exclude_defaults = True ) for hook in webhooks ]
576
+ if webhooks
577
+ else None ,
578
578
)
579
579
580
580
async def abort (
@@ -619,7 +619,7 @@ async def call(
619
619
build : str | None = None ,
620
620
memory_mbytes : int | None = None ,
621
621
timeout : timedelta | None = None ,
622
- webhooks : list [dict ] | None = None ,
622
+ webhooks : list [Webhook ] | None = None ,
623
623
wait : timedelta | None = None ,
624
624
) -> dict | None :
625
625
"""Start an Actor on the Apify Platform and wait for it to finish before returning.
@@ -656,7 +656,9 @@ async def call(
656
656
build = build ,
657
657
memory_mbytes = memory_mbytes ,
658
658
timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
659
- webhooks = webhooks ,
659
+ webhooks = [hook .model_dump (by_alias = True , exclude_defaults = True , exclude_unset = True ) for hook in webhooks ]
660
+ if webhooks
661
+ else [],
660
662
wait_secs = int (wait .total_seconds ()) if wait is not None else None ,
661
663
)
662
664
@@ -668,7 +670,7 @@ async def call_task(
668
670
build : str | None = None ,
669
671
memory_mbytes : int | None = None ,
670
672
timeout : timedelta | None = None ,
671
- webhooks : list [dict ] | None = None ,
673
+ webhooks : list [Webhook ] | None = None ,
672
674
wait : timedelta | None = None ,
673
675
token : str | None = None ,
674
676
) -> dict | None :
@@ -708,7 +710,9 @@ async def call_task(
708
710
build = build ,
709
711
memory_mbytes = memory_mbytes ,
710
712
timeout_secs = int (timeout .total_seconds ()) if timeout is not None else None ,
711
- webhooks = webhooks ,
713
+ webhooks = [hook .model_dump (by_alias = True , exclude_defaults = True , exclude_unset = True ) for hook in webhooks ]
714
+ if webhooks
715
+ else [],
712
716
wait_secs = int (wait .total_seconds ()) if wait is not None else None ,
713
717
)
714
718
@@ -796,10 +800,8 @@ async def reboot(
796
800
797
801
async def add_webhook (
798
802
self ,
803
+ webhook : Webhook ,
799
804
* ,
800
- event_types : list [WebhookEventType ],
801
- request_url : str ,
802
- payload_template : str | None = None ,
803
805
ignore_ssl_errors : bool | None = None ,
804
806
do_not_retry : bool | None = None ,
805
807
idempotency_key : str | None = None ,
@@ -814,9 +816,7 @@ async def add_webhook(
814
816
For more information about Apify Actor webhooks, please see the [documentation](https://docs.apify.com/webhooks).
815
817
816
818
Args:
817
- event_types: List of event types that should trigger the webhook. At least one is required.
818
- request_url: URL that will be invoked once the webhook is triggered.
819
- payload_template: Specification of the payload that will be sent to request_url
819
+ webhook: The webhook to be added
820
820
ignore_ssl_errors: Whether the webhook should ignore SSL errors returned by request_url
821
821
do_not_retry: Whether the webhook should retry sending the payload to request_url upon failure.
822
822
idempotency_key: A unique identifier of a webhook. You can use it to ensure that you won't create
@@ -837,9 +837,9 @@ async def add_webhook(
837
837
838
838
return await self ._apify_client .webhooks ().create (
839
839
actor_run_id = self ._configuration .actor_run_id ,
840
- event_types = event_types ,
841
- request_url = request_url ,
842
- payload_template = payload_template ,
840
+ event_types = webhook . event_types ,
841
+ request_url = webhook . request_url ,
842
+ payload_template = webhook . payload_template ,
843
843
ignore_ssl_errors = ignore_ssl_errors ,
844
844
do_not_retry = do_not_retry ,
845
845
idempotency_key = idempotency_key ,
0 commit comments