diff --git a/docs/02_concepts/14_server_actors.mdx b/docs/02_concepts/14_server_actors.mdx index 506a3d70..5833679c 100644 --- a/docs/02_concepts/14_server_actors.mdx +++ b/docs/02_concepts/14_server_actors.mdx @@ -19,7 +19,7 @@ A [Server Actor](https://docs.apify.com/platform/actors/running/standby) (former :::note Formerly Actor Standby -Actor Standby is the former name of Server Actors, and it'll be deprecated. The platform documentation and the API still use it, for example in the Actor's `standby_url` and `actor_standby` fields, and in the `actor_standby_*` arguments of `ActorClient.update`. In the client, `ActorClient.standby` is a deprecated alias of `ActorClient.server` that will be removed in v4. +Actor Standby is the former name of Server Actors, and it'll be deprecated. The platform documentation and the API still use it, for example in the Actor's `standby_url` and `actor_standby` fields. In the client, `ActorClient.standby` is a deprecated alias of `ActorClient.server`, and the `actor_standby_*` arguments of the Actor and task `update` and `create` methods are deprecated aliases of their `server_*` counterparts, such as `server_build` for `actor_standby_build`. The aliases will be removed in v4. ::: diff --git a/src/apify_client/_resource_clients/actor.py b/src/apify_client/_resource_clients/actor.py index f5d5a430..eddb4177 100644 --- a/src/apify_client/_resource_clients/actor.py +++ b/src/apify_client/_resource_clients/actor.py @@ -9,7 +9,6 @@ from apify_client._models import ( ActorResource, ActorResponse, - ActorStandby, Build, BuildResponse, CreateVersionRequest, @@ -26,6 +25,7 @@ from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync from apify_client._utils.encoding import encode_key_value_store_record_value, encode_webhooks_to_base64 from apify_client._utils.http import response_to_dict +from apify_client._utils.server_args import build_actor_standby from apify_client._utils.time import to_seconds from apify_client._utils.wait_for_resources import ( prepare_resendable_body, @@ -126,6 +126,18 @@ def update( default_run_force_permission_level: ActorPermissionLevel | None = None, example_run_input_body: str | None = None, example_run_input_content_type: str | None = None, + server_is_enabled: bool | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, + server_disable_fields_override: bool | None = None, + server_should_pass_actor_input: bool | None = None, + pricing_infos: list[dict[str, Any]] | None = None, + actor_permission_level: ActorPermissionLevel | None = None, + tagged_builds: dict[str, dict[str, str] | None] | None = None, + timeout: Timeout = 'short', actor_standby_is_enabled: bool | None = None, actor_standby_desired_requests_per_actor_run: int | None = None, actor_standby_max_requests_per_actor_run: int | None = None, @@ -134,10 +146,6 @@ def update( actor_standby_memory_mbytes: int | None = None, actor_standby_disable_standby_fields_override: bool | None = None, actor_standby_should_pass_actor_input: bool | None = None, - pricing_infos: list[dict[str, Any]] | None = None, - actor_permission_level: ActorPermissionLevel | None = None, - tagged_builds: dict[str, dict[str, str] | None] | None = None, - timeout: Timeout = 'short', ) -> ActorResource: """Update the Actor with the specified fields. @@ -165,25 +173,37 @@ def update( example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized as a string (e.g. `json.dumps(input)` for a JSON input). example_run_input_content_type: The content type of the example run input. - actor_standby_is_enabled: Whether the Actor Standby is enabled. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. - actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being - overridden elsewhere. - actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false, - the Standby runs start with no input. + server_is_enabled: Whether the Actor is a Server Actor, which runs a web server called over HTTP. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. + server_disable_fields_override: If true, prevents the Server Actor configuration from being overridden + elsewhere. + server_should_pass_actor_input: Whether to pass the Actor input to the runs of the Server Actor. If false, + they start with no input. pricing_infos: A list of objects that describes the pricing of the Actor. actor_permission_level: The permission level of the Actor on Apify platform. tagged_builds: A dictionary mapping build tag names to their settings. Use it to create, update, or remove build tags. To assign a tag, provide a dict with 'buildId' key. To remove a tag, set its value to None. Example: {'latest': {'buildId': 'abc'}, 'beta': None}. timeout: Timeout for the API HTTP request. + actor_standby_is_enabled: Deprecated alias of `server_is_enabled`. Will be removed in v4. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. + actor_standby_disable_standby_fields_override: Deprecated alias of `server_disable_fields_override`. Will be + removed in v4. + actor_standby_should_pass_actor_input: Deprecated alias of `server_should_pass_actor_input`. Will be removed + in v4. Returns: The updated Actor. @@ -208,15 +228,27 @@ def update( force_permission_level=default_run_force_permission_level, restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - is_enabled=actor_standby_is_enabled, - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, - disable_standby_fields_override=actor_standby_disable_standby_fields_override, - should_pass_actor_input=actor_standby_should_pass_actor_input, + actor_standby=build_actor_standby( + { + 'server_is_enabled': server_is_enabled, + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + 'server_disable_fields_override': server_disable_fields_override, + 'server_should_pass_actor_input': server_should_pass_actor_input, + }, + { + 'actor_standby_is_enabled': actor_standby_is_enabled, + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + 'actor_standby_disable_standby_fields_override': actor_standby_disable_standby_fields_override, + 'actor_standby_should_pass_actor_input': actor_standby_should_pass_actor_input, + }, ), example_run_input=ExampleRunInput( body=example_run_input_body, @@ -728,6 +760,18 @@ async def update( default_run_force_permission_level: ActorPermissionLevel | None = None, example_run_input_body: str | None = None, example_run_input_content_type: str | None = None, + server_is_enabled: bool | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, + server_disable_fields_override: bool | None = None, + server_should_pass_actor_input: bool | None = None, + pricing_infos: list[dict[str, Any]] | None = None, + actor_permission_level: ActorPermissionLevel | None = None, + tagged_builds: dict[str, dict[str, str] | None] | None = None, + timeout: Timeout = 'short', actor_standby_is_enabled: bool | None = None, actor_standby_desired_requests_per_actor_run: int | None = None, actor_standby_max_requests_per_actor_run: int | None = None, @@ -736,10 +780,6 @@ async def update( actor_standby_memory_mbytes: int | None = None, actor_standby_disable_standby_fields_override: bool | None = None, actor_standby_should_pass_actor_input: bool | None = None, - pricing_infos: list[dict[str, Any]] | None = None, - actor_permission_level: ActorPermissionLevel | None = None, - tagged_builds: dict[str, dict[str, str] | None] | None = None, - timeout: Timeout = 'short', ) -> ActorResource: """Update the Actor with the specified fields. @@ -767,25 +807,37 @@ async def update( example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized as a string (e.g. `json.dumps(input)` for a JSON input). example_run_input_content_type: The content type of the example run input. - actor_standby_is_enabled: Whether the Actor Standby is enabled. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. - actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being - overridden elsewhere. - actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false, - the Standby runs start with no input. + server_is_enabled: Whether the Actor is a Server Actor, which runs a web server called over HTTP. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. + server_disable_fields_override: If true, prevents the Server Actor configuration from being overridden + elsewhere. + server_should_pass_actor_input: Whether to pass the Actor input to the runs of the Server Actor. If false, + they start with no input. pricing_infos: A list of objects that describes the pricing of the Actor. actor_permission_level: The permission level of the Actor on Apify platform. tagged_builds: A dictionary mapping build tag names to their settings. Use it to create, update, or remove build tags. To assign a tag, provide a dict with 'buildId' key. To remove a tag, set its value to None. Example: {'latest': {'buildId': 'abc'}, 'beta': None}. timeout: Timeout for the API HTTP request. + actor_standby_is_enabled: Deprecated alias of `server_is_enabled`. Will be removed in v4. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. + actor_standby_disable_standby_fields_override: Deprecated alias of `server_disable_fields_override`. Will be + removed in v4. + actor_standby_should_pass_actor_input: Deprecated alias of `server_should_pass_actor_input`. Will be removed + in v4. Returns: The updated Actor. @@ -810,15 +862,27 @@ async def update( force_permission_level=default_run_force_permission_level, restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - is_enabled=actor_standby_is_enabled, - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, - disable_standby_fields_override=actor_standby_disable_standby_fields_override, - should_pass_actor_input=actor_standby_should_pass_actor_input, + actor_standby=build_actor_standby( + { + 'server_is_enabled': server_is_enabled, + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + 'server_disable_fields_override': server_disable_fields_override, + 'server_should_pass_actor_input': server_should_pass_actor_input, + }, + { + 'actor_standby_is_enabled': actor_standby_is_enabled, + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + 'actor_standby_disable_standby_fields_override': actor_standby_disable_standby_fields_override, + 'actor_standby_should_pass_actor_input': actor_standby_should_pass_actor_input, + }, ), example_run_input=ExampleRunInput( body=example_run_input_body, diff --git a/src/apify_client/_resource_clients/actor_collection.py b/src/apify_client/_resource_clients/actor_collection.py index 3d20423b..530a9f46 100644 --- a/src/apify_client/_resource_clients/actor_collection.py +++ b/src/apify_client/_resource_clients/actor_collection.py @@ -6,7 +6,6 @@ from apify_client._models import ( ActorResource, ActorResponse, - ActorStandby, CreateActorRequest, DefaultRunOptions, ExampleRunInput, @@ -15,6 +14,7 @@ ) from apify_client._pagination import get_items_iterator, get_items_iterator_async from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync +from apify_client._utils.server_args import build_actor_standby from apify_client._utils.time import to_seconds if TYPE_CHECKING: @@ -129,6 +129,16 @@ def create( default_run_force_permission_level: ActorPermissionLevel | None = None, example_run_input_body: str | None = None, example_run_input_content_type: str | None = None, + server_is_enabled: bool | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, + server_disable_fields_override: bool | None = None, + server_should_pass_actor_input: bool | None = None, + actor_permission_level: ActorPermissionLevel | None = None, + timeout: Timeout = 'medium', actor_standby_is_enabled: bool | None = None, actor_standby_desired_requests_per_actor_run: int | None = None, actor_standby_max_requests_per_actor_run: int | None = None, @@ -137,8 +147,6 @@ def create( actor_standby_memory_mbytes: int | None = None, actor_standby_disable_standby_fields_override: bool | None = None, actor_standby_should_pass_actor_input: bool | None = None, - actor_permission_level: ActorPermissionLevel | None = None, - timeout: Timeout = 'medium', ) -> ActorResource: """Create a new Actor. @@ -166,21 +174,33 @@ def create( example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized as a string (e.g. `json.dumps(input)` for a JSON input). example_run_input_content_type: The content type of the example run input. - actor_standby_is_enabled: Whether the Actor Standby is enabled. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. - actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being - overridden elsewhere. - actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false, - the Standby runs start with no input. + server_is_enabled: Whether the Actor is a Server Actor, which runs a web server called over HTTP. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. + server_disable_fields_override: If true, prevents the Server Actor configuration from being overridden + elsewhere. + server_should_pass_actor_input: Whether to pass the Actor input to the runs of the Server Actor. If false, + they start with no input. actor_permission_level: The permission level of the Actor on Apify platform. timeout: Timeout for the API HTTP request. + actor_standby_is_enabled: Deprecated alias of `server_is_enabled`. Will be removed in v4. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. + actor_standby_disable_standby_fields_override: Deprecated alias of `server_disable_fields_override`. Will be + removed in v4. + actor_standby_should_pass_actor_input: Deprecated alias of `server_should_pass_actor_input`. Will be removed + in v4. Returns: The created Actor. @@ -204,15 +224,27 @@ def create( force_permission_level=default_run_force_permission_level, restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - is_enabled=actor_standby_is_enabled, - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, - disable_standby_fields_override=actor_standby_disable_standby_fields_override, - should_pass_actor_input=actor_standby_should_pass_actor_input, + actor_standby=build_actor_standby( + { + 'server_is_enabled': server_is_enabled, + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + 'server_disable_fields_override': server_disable_fields_override, + 'server_should_pass_actor_input': server_should_pass_actor_input, + }, + { + 'actor_standby_is_enabled': actor_standby_is_enabled, + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + 'actor_standby_disable_standby_fields_override': actor_standby_disable_standby_fields_override, + 'actor_standby_should_pass_actor_input': actor_standby_should_pass_actor_input, + }, ), example_run_input=ExampleRunInput( body=example_run_input_body, @@ -326,6 +358,16 @@ async def create( default_run_force_permission_level: ActorPermissionLevel | None = None, example_run_input_body: str | None = None, example_run_input_content_type: str | None = None, + server_is_enabled: bool | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, + server_disable_fields_override: bool | None = None, + server_should_pass_actor_input: bool | None = None, + actor_permission_level: ActorPermissionLevel | None = None, + timeout: Timeout = 'medium', actor_standby_is_enabled: bool | None = None, actor_standby_desired_requests_per_actor_run: int | None = None, actor_standby_max_requests_per_actor_run: int | None = None, @@ -334,8 +376,6 @@ async def create( actor_standby_memory_mbytes: int | None = None, actor_standby_disable_standby_fields_override: bool | None = None, actor_standby_should_pass_actor_input: bool | None = None, - actor_permission_level: ActorPermissionLevel | None = None, - timeout: Timeout = 'medium', ) -> ActorResource: """Create a new Actor. @@ -363,21 +403,33 @@ async def create( example_run_input_body: Input to be prefilled as default input to new users of this Actor, serialized as a string (e.g. `json.dumps(input)` for a JSON input). example_run_input_content_type: The content type of the example run input. - actor_standby_is_enabled: Whether the Actor Standby is enabled. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. - actor_standby_disable_standby_fields_override: If true, prevents the Standby configuration from being - overridden elsewhere. - actor_standby_should_pass_actor_input: Whether to pass the Actor input to the Standby runs. If false, - the Standby runs start with no input. + server_is_enabled: Whether the Actor is a Server Actor, which runs a web server called over HTTP. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. + server_disable_fields_override: If true, prevents the Server Actor configuration from being overridden + elsewhere. + server_should_pass_actor_input: Whether to pass the Actor input to the runs of the Server Actor. If false, + they start with no input. actor_permission_level: The permission level of the Actor on Apify platform. timeout: Timeout for the API HTTP request. + actor_standby_is_enabled: Deprecated alias of `server_is_enabled`. Will be removed in v4. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. + actor_standby_disable_standby_fields_override: Deprecated alias of `server_disable_fields_override`. Will be + removed in v4. + actor_standby_should_pass_actor_input: Deprecated alias of `server_should_pass_actor_input`. Will be removed + in v4. Returns: The created Actor. @@ -401,15 +453,27 @@ async def create( force_permission_level=default_run_force_permission_level, restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - is_enabled=actor_standby_is_enabled, - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, - disable_standby_fields_override=actor_standby_disable_standby_fields_override, - should_pass_actor_input=actor_standby_should_pass_actor_input, + actor_standby=build_actor_standby( + { + 'server_is_enabled': server_is_enabled, + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + 'server_disable_fields_override': server_disable_fields_override, + 'server_should_pass_actor_input': server_should_pass_actor_input, + }, + { + 'actor_standby_is_enabled': actor_standby_is_enabled, + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + 'actor_standby_disable_standby_fields_override': actor_standby_disable_standby_fields_override, + 'actor_standby_should_pass_actor_input': actor_standby_should_pass_actor_input, + }, ), example_run_input=ExampleRunInput( body=example_run_input_body, diff --git a/src/apify_client/_resource_clients/task.py b/src/apify_client/_resource_clients/task.py index 178a7fe7..20755701 100644 --- a/src/apify_client/_resource_clients/task.py +++ b/src/apify_client/_resource_clients/task.py @@ -4,7 +4,6 @@ from apify_client._docs import docs_group from apify_client._models import ( - ActorStandby, Run, RunResponse, Task, @@ -17,6 +16,7 @@ from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync from apify_client._utils.encoding import encode_webhooks_to_base64 from apify_client._utils.http import response_to_dict +from apify_client._utils.server_args import build_actor_standby from apify_client._utils.time import to_seconds from apify_client._utils.wait_for_resources import start_waiting_for_resources, start_waiting_for_resources_async @@ -83,11 +83,11 @@ def update( restart_on_error: bool | None = None, title: str | None = None, description: str | None = None, - actor_standby_desired_requests_per_actor_run: int | None = None, - actor_standby_max_requests_per_actor_run: int | None = None, - actor_standby_idle_timeout: timedelta | None = None, - actor_standby_build: str | None = None, - actor_standby_memory_mbytes: int | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, is_public: bool | None = None, public_config_seo_title: str | None = None, public_config_seo_description: str | None = None, @@ -95,6 +95,11 @@ def update( public_config_dataset_name: str | None = None, public_config_dataset_view: str | None = None, timeout: Timeout = 'short', + actor_standby_desired_requests_per_actor_run: int | None = None, + actor_standby_max_requests_per_actor_run: int | None = None, + actor_standby_idle_timeout: timedelta | None = None, + actor_standby_build: str | None = None, + actor_standby_memory_mbytes: int | None = None, ) -> Task: """Update the task with specified fields. @@ -116,14 +121,14 @@ def update( task_input: Task input dictionary. title: A human-friendly equivalent of the name. description: Description of the task. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. is_public: Set to `True` to publish the task on its public landing page, or `False` to unpublish it. Passing the value the task already has does nothing. Publishing requires the public display configuration to be filled in, and write access to the task's Actor. @@ -135,6 +140,13 @@ def update( displayed on the public task page. public_config_dataset_view: View key from the Actor's dataset schema shown on the public task page. timeout: Timeout for the API HTTP request. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. Returns: The updated task. @@ -163,12 +175,21 @@ def update( timeout_secs=to_seconds(run_timeout, as_int=True), restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, + actor_standby=build_actor_standby( + { + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + }, + { + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + }, ), ) result = self._update(timeout=timeout, **task_fields.model_dump(by_alias=True, exclude_none=True)) @@ -499,11 +520,11 @@ async def update( restart_on_error: bool | None = None, title: str | None = None, description: str | None = None, - actor_standby_desired_requests_per_actor_run: int | None = None, - actor_standby_max_requests_per_actor_run: int | None = None, - actor_standby_idle_timeout: timedelta | None = None, - actor_standby_build: str | None = None, - actor_standby_memory_mbytes: int | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, is_public: bool | None = None, public_config_seo_title: str | None = None, public_config_seo_description: str | None = None, @@ -511,6 +532,11 @@ async def update( public_config_dataset_name: str | None = None, public_config_dataset_view: str | None = None, timeout: Timeout = 'short', + actor_standby_desired_requests_per_actor_run: int | None = None, + actor_standby_max_requests_per_actor_run: int | None = None, + actor_standby_idle_timeout: timedelta | None = None, + actor_standby_build: str | None = None, + actor_standby_memory_mbytes: int | None = None, ) -> Task: """Update the task with specified fields. @@ -532,14 +558,14 @@ async def update( task_input: Task input dictionary. title: A human-friendly equivalent of the name. description: Description of the task. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. is_public: Set to `True` to publish the task on its public landing page, or `False` to unpublish it. Passing the value the task already has does nothing. Publishing requires the public display configuration to be filled in, and write access to the task's Actor. @@ -551,6 +577,13 @@ async def update( displayed on the public task page. public_config_dataset_view: View key from the Actor's dataset schema shown on the public task page. timeout: Timeout for the API HTTP request. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. Returns: The updated task. @@ -579,12 +612,21 @@ async def update( timeout_secs=to_seconds(run_timeout, as_int=True), restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, + actor_standby=build_actor_standby( + { + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + }, + { + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + }, ), ) result = await self._update(timeout=timeout, **task_fields.model_dump(by_alias=True, exclude_none=True)) diff --git a/src/apify_client/_resource_clients/task_collection.py b/src/apify_client/_resource_clients/task_collection.py index 348efb52..ae6e5bcc 100644 --- a/src/apify_client/_resource_clients/task_collection.py +++ b/src/apify_client/_resource_clients/task_collection.py @@ -4,7 +4,6 @@ from apify_client._docs import docs_group from apify_client._models import ( - ActorStandby, CreateTaskRequest, ListOfTasks, ListOfTasksResponse, @@ -16,6 +15,7 @@ ) from apify_client._pagination import get_items_iterator, get_items_iterator_async from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync +from apify_client._utils.server_args import build_actor_standby from apify_client._utils.time import to_seconds if TYPE_CHECKING: @@ -117,17 +117,22 @@ def create( task_input: TaskInputDict | TaskInput | None = None, title: str | None = None, description: str | None = None, - actor_standby_desired_requests_per_actor_run: int | None = None, - actor_standby_max_requests_per_actor_run: int | None = None, - actor_standby_idle_timeout: timedelta | None = None, - actor_standby_build: str | None = None, - actor_standby_memory_mbytes: int | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, public_config_seo_title: str | None = None, public_config_seo_description: str | None = None, public_config_input_schema_fields: list[str] | None = None, # ty: ignore[invalid-type-form] public_config_dataset_name: str | None = None, public_config_dataset_view: str | None = None, timeout: Timeout = 'medium', + actor_standby_desired_requests_per_actor_run: int | None = None, + actor_standby_max_requests_per_actor_run: int | None = None, + actor_standby_idle_timeout: timedelta | None = None, + actor_standby_build: str | None = None, + actor_standby_memory_mbytes: int | None = None, ) -> Task: """Create a new task. @@ -153,14 +158,14 @@ def create( task_input: Task input object. title: A human-friendly equivalent of the name. description: Description of the task. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. public_config_seo_title: SEO title of the public task page. Defaults to the task title when not set. public_config_seo_description: SEO description of the public task page. Defaults to the task description when not set. @@ -169,6 +174,13 @@ def create( displayed on the public task page. public_config_dataset_view: View key from the Actor's dataset schema shown on the public task page. timeout: Timeout for the API HTTP request. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. Returns: The created task. @@ -197,12 +209,21 @@ def create( timeout_secs=to_seconds(run_timeout, as_int=True), restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, + actor_standby=build_actor_standby( + { + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + }, + { + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + }, ), ) result = self._create(timeout=timeout, **task_fields.model_dump(by_alias=True, exclude_none=True)) @@ -298,17 +319,22 @@ async def create( task_input: TaskInputDict | TaskInput | None = None, title: str | None = None, description: str | None = None, - actor_standby_desired_requests_per_actor_run: int | None = None, - actor_standby_max_requests_per_actor_run: int | None = None, - actor_standby_idle_timeout: timedelta | None = None, - actor_standby_build: str | None = None, - actor_standby_memory_mbytes: int | None = None, + server_desired_requests_per_actor_run: int | None = None, + server_max_requests_per_actor_run: int | None = None, + server_idle_timeout: timedelta | None = None, + server_build: str | None = None, + server_memory_mbytes: int | None = None, public_config_seo_title: str | None = None, public_config_seo_description: str | None = None, public_config_input_schema_fields: list[str] | None = None, # ty: ignore[invalid-type-form] public_config_dataset_name: str | None = None, public_config_dataset_view: str | None = None, timeout: Timeout = 'medium', + actor_standby_desired_requests_per_actor_run: int | None = None, + actor_standby_max_requests_per_actor_run: int | None = None, + actor_standby_idle_timeout: timedelta | None = None, + actor_standby_build: str | None = None, + actor_standby_memory_mbytes: int | None = None, ) -> Task: """Create a new task. @@ -334,14 +360,14 @@ async def create( task_input: Task input object. title: A human-friendly equivalent of the name. description: Description of the task. - actor_standby_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for - a single Actor Standby run. - actor_standby_idle_timeout: If the Actor run does not receive any requests for this time, - it will be shut down. - actor_standby_build: The build tag or number to run when the Actor is in Standby mode. - actor_standby_memory_mbytes: The memory in megabytes to use when the Actor is in Standby mode. + server_desired_requests_per_actor_run: The desired number of concurrent HTTP requests for a single run of + the Server Actor. + server_max_requests_per_actor_run: The maximum number of concurrent HTTP requests for a single run of the + Server Actor. + server_idle_timeout: If a run of the Server Actor does not receive any requests for this time, it is shut + down. + server_build: The build tag or number that the Server Actor runs. + server_memory_mbytes: The memory in megabytes for the runs of the Server Actor. public_config_seo_title: SEO title of the public task page. Defaults to the task title when not set. public_config_seo_description: SEO description of the public task page. Defaults to the task description when not set. @@ -350,6 +376,13 @@ async def create( displayed on the public task page. public_config_dataset_view: View key from the Actor's dataset schema shown on the public task page. timeout: Timeout for the API HTTP request. + actor_standby_desired_requests_per_actor_run: Deprecated alias of `server_desired_requests_per_actor_run`. + Will be removed in v4. + actor_standby_max_requests_per_actor_run: Deprecated alias of `server_max_requests_per_actor_run`. Will be + removed in v4. + actor_standby_idle_timeout: Deprecated alias of `server_idle_timeout`. Will be removed in v4. + actor_standby_build: Deprecated alias of `server_build`. Will be removed in v4. + actor_standby_memory_mbytes: Deprecated alias of `server_memory_mbytes`. Will be removed in v4. Returns: The created task. @@ -378,12 +411,21 @@ async def create( timeout_secs=to_seconds(run_timeout, as_int=True), restart_on_error=restart_on_error, ), - actor_standby=ActorStandby( - desired_requests_per_actor_run=actor_standby_desired_requests_per_actor_run, - max_requests_per_actor_run=actor_standby_max_requests_per_actor_run, - idle_timeout_secs=to_seconds(actor_standby_idle_timeout, as_int=True), - build=actor_standby_build, - memory_mbytes=actor_standby_memory_mbytes, + actor_standby=build_actor_standby( + { + 'server_desired_requests_per_actor_run': server_desired_requests_per_actor_run, + 'server_max_requests_per_actor_run': server_max_requests_per_actor_run, + 'server_idle_timeout': server_idle_timeout, + 'server_build': server_build, + 'server_memory_mbytes': server_memory_mbytes, + }, + { + 'actor_standby_desired_requests_per_actor_run': actor_standby_desired_requests_per_actor_run, + 'actor_standby_max_requests_per_actor_run': actor_standby_max_requests_per_actor_run, + 'actor_standby_idle_timeout': actor_standby_idle_timeout, + 'actor_standby_build': actor_standby_build, + 'actor_standby_memory_mbytes': actor_standby_memory_mbytes, + }, ), ) result = await self._create(timeout=timeout, **task_fields.model_dump(by_alias=True, exclude_none=True)) diff --git a/src/apify_client/_utils/server_args.py b/src/apify_client/_utils/server_args.py new file mode 100644 index 00000000..bfdaed8c --- /dev/null +++ b/src/apify_client/_utils/server_args.py @@ -0,0 +1,60 @@ +from __future__ import annotations + +import warnings +from typing import Any + +from apify_client._models import ActorStandby +from apify_client._utils.time import to_seconds + +DEPRECATED_SERVER_ARGS = { + 'actor_standby_is_enabled': 'server_is_enabled', + 'actor_standby_desired_requests_per_actor_run': 'server_desired_requests_per_actor_run', + 'actor_standby_max_requests_per_actor_run': 'server_max_requests_per_actor_run', + 'actor_standby_idle_timeout': 'server_idle_timeout', + 'actor_standby_build': 'server_build', + 'actor_standby_memory_mbytes': 'server_memory_mbytes', + 'actor_standby_disable_standby_fields_override': 'server_disable_fields_override', + 'actor_standby_should_pass_actor_input': 'server_should_pass_actor_input', +} +"""Deprecated `actor_standby_*` arguments, named after Actor Standby (the former name of Server Actors), mapped to the +`server_*` arguments that replace them.""" + + +def build_actor_standby(server_args: dict[str, Any], deprecated_args: dict[str, Any]) -> ActorStandby: + """Build the `actorStandby` field of an Actor or task from its `server_*` arguments. + + Each set deprecated `actor_standby_*` argument emits a `DeprecationWarning` pointing at the caller of the public + method and is used as its `server_*` counterpart. + + Args: + server_args: The `server_*` arguments by name. + deprecated_args: The deprecated `actor_standby_*` arguments by name. + + Raises: + ValueError: If both a deprecated argument and its `server_*` counterpart are set. + """ + args = dict(server_args) + for deprecated_name, value in deprecated_args.items(): + if value is None: + continue + name = DEPRECATED_SERVER_ARGS[deprecated_name] + # Skips this helper, the public method, and the `WithLogDetailsClient` wrapper around it. + warnings.warn( + f'The `{deprecated_name}` argument is deprecated and will be removed in v4. Use `{name}` instead.', + DeprecationWarning, + stacklevel=4, + ) + if args.get(name) is not None: + raise ValueError(f'Pass only one of `{name}` and `{deprecated_name}`.') + args[name] = value + + return ActorStandby( + is_enabled=args.get('server_is_enabled'), + desired_requests_per_actor_run=args.get('server_desired_requests_per_actor_run'), + max_requests_per_actor_run=args.get('server_max_requests_per_actor_run'), + idle_timeout_secs=to_seconds(args.get('server_idle_timeout'), as_int=True), + build=args.get('server_build'), + memory_mbytes=args.get('server_memory_mbytes'), + disable_standby_fields_override=args.get('server_disable_fields_override'), + should_pass_actor_input=args.get('server_should_pass_actor_input'), + ) diff --git a/tests/integration/test_actor_server.py b/tests/integration/test_actor_server.py index 9045cb78..895eac0d 100644 --- a/tests/integration/test_actor_server.py +++ b/tests/integration/test_actor_server.py @@ -73,9 +73,9 @@ def server_actor_id(api_token: str) -> Generator[str]: ], } ], - actor_standby_is_enabled=True, - actor_standby_memory_mbytes=256, - actor_standby_idle_timeout=timedelta(minutes=1), + server_is_enabled=True, + server_memory_mbytes=256, + server_idle_timeout=timedelta(minutes=1), ) actor_client = client.actor(actor.id) diff --git a/tests/unit/test_actor_server.py b/tests/unit/test_actor_server.py index b80f1533..018f738e 100644 --- a/tests/unit/test_actor_server.py +++ b/tests/unit/test_actor_server.py @@ -557,9 +557,9 @@ def handler(request: Request) -> Response: def expect_server_actor_with_build( - httpserver: HTTPServer, *, standby_build: str | None, build_id: str, actor_definition: dict[str, Any] | None + httpserver: HTTPServer, *, server_build: str | None, build_id: str, actor_definition: dict[str, Any] | None ) -> None: - actor_standby = {'isEnabled': True, 'build': standby_build} + actor_standby = {'isEnabled': True, 'build': server_build} httpserver.expect_request(_ACTOR_PATH, method='GET').respond_with_json( actor_response(httpserver.url_for(_SERVER_PREFIX), taggedBuilds=_TAGGED_BUILDS, actorStandby=actor_standby) ) @@ -569,18 +569,18 @@ def expect_server_actor_with_build( @pytest.mark.parametrize( - ('standby_build', 'build_id'), + ('server_build', 'build_id'), [ pytest.param(None, 'latest_build_id', id='no build set uses latest'), pytest.param('beta', 'beta_build_id', id='build tag'), ], ) def test_get_openapi_spec_from_tagged_build( - httpserver: HTTPServer, sync_client: ApifyClient, standby_build: str | None, build_id: str + httpserver: HTTPServer, sync_client: ApifyClient, server_build: str | None, build_id: str ) -> None: """The specification comes from the web server schema of the tagged build that serves the server interface.""" expect_server_actor_with_build( - httpserver, standby_build=standby_build, build_id=build_id, actor_definition={'webServerSchema': _OPENAPI_SPEC} + httpserver, server_build=server_build, build_id=build_id, actor_definition={'webServerSchema': _OPENAPI_SPEC} ) assert sync_client.actor(_MOCKED_ACTOR_ID).server().get_openapi_spec() == _OPENAPI_SPEC @@ -589,7 +589,7 @@ def test_get_openapi_spec_from_tagged_build( async def test_get_openapi_spec_from_tagged_build_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: """Async variant of `test_get_openapi_spec_from_tagged_build`.""" expect_server_actor_with_build( - httpserver, standby_build='beta', build_id='beta_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} + httpserver, server_build='beta', build_id='beta_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} ) assert await async_client.actor(_MOCKED_ACTOR_ID).server().get_openapi_spec() == _OPENAPI_SPEC @@ -598,7 +598,7 @@ async def test_get_openapi_spec_from_tagged_build_async(httpserver: HTTPServer, def test_get_openapi_spec_from_build_number(httpserver: HTTPServer, sync_client: ApifyClient) -> None: """A build number set for the server interface is looked up in the Actor's builds.""" expect_server_actor_with_build( - httpserver, standby_build='0.0.1', build_id='old_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} + httpserver, server_build='0.0.1', build_id='old_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} ) expect_builds_list(httpserver, {'latest_build_id': '0.0.2', 'old_build_id': '0.0.1'}) @@ -610,7 +610,7 @@ def test_get_openapi_spec_passes_timeout_to_every_api_call( ) -> None: """The timeout of `get_openapi_spec` applies to fetching the Actor, listing its builds, and fetching the build.""" expect_server_actor_with_build( - httpserver, standby_build='0.0.1', build_id='old_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} + httpserver, server_build='0.0.1', build_id='old_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} ) expect_builds_list(httpserver, {'old_build_id': '0.0.1'}) call = Mock(wraps=sync_client.http_client.call) @@ -626,7 +626,7 @@ def test_request_reuses_server_url_fetched_by_get_openapi_spec( ) -> None: """A request after `get_openapi_spec` reuses the server URL it fetched.""" expect_server_actor_with_build( - httpserver, standby_build=None, build_id='latest_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} + httpserver, server_build=None, build_id='latest_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} ) httpserver.expect_request(f'{_SERVER_PREFIX}/', method='GET').respond_with_json({'ok': True}) actor_server_client = sync_client.actor(_MOCKED_ACTOR_ID).server() @@ -654,7 +654,7 @@ def test_get_url_passes_timeout( async def test_get_openapi_spec_from_build_number_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: """Async variant of `test_get_openapi_spec_from_build_number`.""" expect_server_actor_with_build( - httpserver, standby_build='0.0.1', build_id='old_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} + httpserver, server_build='0.0.1', build_id='old_build_id', actor_definition={'webServerSchema': _OPENAPI_SPEC} ) expect_builds_list(httpserver, {'latest_build_id': '0.0.2', 'old_build_id': '0.0.1'}) @@ -673,7 +673,7 @@ def test_get_openapi_spec_without_schema_returns_none( ) -> None: """A build without a web server schema has no specification to return.""" expect_server_actor_with_build( - httpserver, standby_build=None, build_id='latest_build_id', actor_definition=actor_definition + httpserver, server_build=None, build_id='latest_build_id', actor_definition=actor_definition ) assert sync_client.actor(_MOCKED_ACTOR_ID).server().get_openapi_spec() is None @@ -681,7 +681,7 @@ def test_get_openapi_spec_without_schema_returns_none( def test_get_openapi_spec_unknown_build_raises(httpserver: HTTPServer, sync_client: ApifyClient) -> None: """A server interface build that is neither a tag nor a listed build number raises an error.""" - expect_server_actor_with_build(httpserver, standby_build='9.9.9', build_id='unused_build_id', actor_definition=None) + expect_server_actor_with_build(httpserver, server_build='9.9.9', build_id='unused_build_id', actor_definition=None) expect_builds_list(httpserver, {'latest_build_id': '0.0.2'}) with pytest.raises(ApifyClientError, match='does not exist'): @@ -704,7 +704,7 @@ def one_build_per_page(request: Request) -> Response: return Response(json.dumps({'data': data}), content_type='application/json') handler = Mock(side_effect=one_build_per_page) - expect_server_actor_with_build(httpserver, standby_build='0.0.4', build_id='unused_build_id', actor_definition=None) + expect_server_actor_with_build(httpserver, server_build='0.0.4', build_id='unused_build_id', actor_definition=None) httpserver.expect_request(f'{_ACTOR_PATH}/builds', method='GET').respond_with_handler(handler) with pytest.raises(ApifyClientError, match='does not exist'): @@ -718,7 +718,7 @@ def test_get_openapi_spec_unknown_tag_raises_without_listing_builds( ) -> None: """A server interface build that is neither a tag nor a build number raises without listing the builds.""" expect_server_actor_with_build( - httpserver, standby_build='nightly', build_id='unused_build_id', actor_definition=None + httpserver, server_build='nightly', build_id='unused_build_id', actor_definition=None ) with pytest.raises(ApifyClientError, match='Build nightly of Actor'): diff --git a/tests/unit/test_actor_update_fields.py b/tests/unit/test_actor_update_fields.py index d6060b0e..112be869 100644 --- a/tests/unit/test_actor_update_fields.py +++ b/tests/unit/test_actor_update_fields.py @@ -35,6 +35,11 @@ } _FIELDS: dict[str, Any] = { + 'server_disable_fields_override': True, + 'server_should_pass_actor_input': False, +} + +_DEPRECATED_FIELDS: dict[str, Any] = { 'actor_standby_disable_standby_fields_override': True, 'actor_standby_should_pass_actor_input': False, } @@ -57,8 +62,8 @@ def body_subset(request: Request) -> dict[str, Any]: return {key: body[key] for key in _EXPECTED_BODY} -def test_update_sends_standby_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None: - """`update` nests the Standby flags into `actorStandby`.""" +def test_update_sends_server_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """`update` nests the `server_*` arguments into `actorStandby`.""" captured: list[Request] = [] httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured)) @@ -68,8 +73,8 @@ def test_update_sends_standby_fields(httpserver: HTTPServer, sync_client: ApifyC assert body_subset(captured[0]) == _EXPECTED_BODY -async def test_update_sends_standby_fields_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: - """Async `update` nests the Standby flags into `actorStandby`.""" +async def test_update_sends_server_fields_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: + """Async `update` nests the `server_*` arguments into `actorStandby`.""" captured: list[Request] = [] httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured)) @@ -79,8 +84,8 @@ async def test_update_sends_standby_fields_async(httpserver: HTTPServer, async_c assert body_subset(captured[0]) == _EXPECTED_BODY -def test_create_sends_standby_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None: - """`create` nests the Standby flags into `actorStandby`.""" +def test_create_sends_server_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """`create` nests the `server_*` arguments into `actorStandby`.""" captured: list[Request] = [] httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured)) @@ -90,8 +95,8 @@ def test_create_sends_standby_fields(httpserver: HTTPServer, sync_client: ApifyC assert body_subset(captured[0]) == _EXPECTED_BODY -async def test_create_sends_standby_fields_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: - """Async `create` nests the Standby flags into `actorStandby`.""" +async def test_create_sends_server_fields_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: + """Async `create` nests the `server_*` arguments into `actorStandby`.""" captured: list[Request] = [] httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured)) @@ -101,6 +106,71 @@ async def test_create_sends_standby_fields_async(httpserver: HTTPServer, async_c assert body_subset(captured[0]) == _EXPECTED_BODY +def test_update_deprecated_standby_args_are_aliases(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """The deprecated `actor_standby_*` arguments of `update` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + sync_client.actor(_MOCKED_ACTOR_ID).update(**_DEPRECATED_FIELDS) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert body_subset(captured[0]) == _EXPECTED_BODY + + +async def test_update_deprecated_standby_args_are_aliases_async( + httpserver: HTTPServer, async_client: ApifyClientAsync +) -> None: + """The deprecated `actor_standby_*` arguments of async `update` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_ACTOR_PATH, method='PUT').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + await async_client.actor(_MOCKED_ACTOR_ID).update(**_DEPRECATED_FIELDS) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert body_subset(captured[0]) == _EXPECTED_BODY + + +def test_create_deprecated_standby_args_are_aliases(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """The deprecated `actor_standby_*` arguments of `create` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + sync_client.actors().create(name='test-actor', **_DEPRECATED_FIELDS) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert body_subset(captured[0]) == _EXPECTED_BODY + + +async def test_create_deprecated_standby_args_are_aliases_async( + httpserver: HTTPServer, async_client: ApifyClientAsync +) -> None: + """The deprecated `actor_standby_*` arguments of async `create` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_ACTORS_PATH, method='POST').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + await async_client.actors().create(name='test-actor', **_DEPRECATED_FIELDS) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert body_subset(captured[0]) == _EXPECTED_BODY + + +def test_update_rejects_server_arg_and_its_deprecated_alias(sync_client: ApifyClient) -> None: + """Passing both a `server_*` argument and its deprecated `actor_standby_*` alias raises a `ValueError`.""" + with ( + pytest.warns(DeprecationWarning, match='`actor_standby_build` argument is deprecated'), + pytest.raises(ValueError, match='only one of `server_build` and `actor_standby_build`'), + ): + sync_client.actor(_MOCKED_ACTOR_ID).update(server_build='latest', actor_standby_build='beta') + + def test_create_sends_actor_permission_level(httpserver: HTTPServer, sync_client: ApifyClient) -> None: """`create` sends `actor_permission_level` as `actorPermissionLevel`.""" captured: list[Request] = [] diff --git a/tests/unit/test_task_update_fields.py b/tests/unit/test_task_update_fields.py index 2ab0a7d6..efe80268 100644 --- a/tests/unit/test_task_update_fields.py +++ b/tests/unit/test_task_update_fields.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +from datetime import timedelta from decimal import Decimal from typing import TYPE_CHECKING, Any @@ -101,3 +102,129 @@ async def test_create_sends_description_and_max_total_charge_async( assert len(captured) == 1 assert body_subset(captured[0]) == _EXPECTED_BODY + + +_SERVER_EXPECTED_BODY = {'actorStandby': {'build': 'beta', 'idleTimeoutSecs': 90}} + + +def server_body(request: Request) -> dict[str, Any]: + body = json.loads(request.get_data()) + return {'actorStandby': body['actorStandby']} + + +def test_update_sends_server_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """`update` nests the `server_*` arguments into `actorStandby`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASK_PATH, method='PUT').respond_with_handler(capture(captured)) + + sync_client.task(_MOCKED_TASK_ID).update(server_build='beta', server_idle_timeout=timedelta(seconds=90)) + + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +async def test_update_sends_server_fields_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: + """Async `update` nests the `server_*` arguments into `actorStandby`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASK_PATH, method='PUT').respond_with_handler(capture(captured)) + + await async_client.task(_MOCKED_TASK_ID).update(server_build='beta', server_idle_timeout=timedelta(seconds=90)) + + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +def test_update_deprecated_standby_args_are_aliases(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """The deprecated `actor_standby_*` arguments of `update` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASK_PATH, method='PUT').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + sync_client.task(_MOCKED_TASK_ID).update( + actor_standby_build='beta', actor_standby_idle_timeout=timedelta(seconds=90) + ) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +async def test_update_deprecated_standby_args_are_aliases_async( + httpserver: HTTPServer, async_client: ApifyClientAsync +) -> None: + """The deprecated `actor_standby_*` arguments of async `update` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASK_PATH, method='PUT').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + await async_client.task(_MOCKED_TASK_ID).update( + actor_standby_build='beta', actor_standby_idle_timeout=timedelta(seconds=90) + ) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +def test_create_sends_server_fields(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """`create` nests the `server_*` arguments into `actorStandby`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASKS_PATH, method='POST').respond_with_handler(capture(captured)) + + sync_client.tasks().create( + actor_id='test_actor_id', name='test-task', server_build='beta', server_idle_timeout=timedelta(seconds=90) + ) + + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +async def test_create_sends_server_fields_async(httpserver: HTTPServer, async_client: ApifyClientAsync) -> None: + """Async `create` nests the `server_*` arguments into `actorStandby`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASKS_PATH, method='POST').respond_with_handler(capture(captured)) + + await async_client.tasks().create( + actor_id='test_actor_id', name='test-task', server_build='beta', server_idle_timeout=timedelta(seconds=90) + ) + + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +def test_create_deprecated_standby_args_are_aliases(httpserver: HTTPServer, sync_client: ApifyClient) -> None: + """The deprecated `actor_standby_*` arguments of `create` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASKS_PATH, method='POST').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + sync_client.tasks().create( + actor_id='test_actor_id', + name='test-task', + actor_standby_build='beta', + actor_standby_idle_timeout=timedelta(seconds=90), + ) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY + + +async def test_create_deprecated_standby_args_are_aliases_async( + httpserver: HTTPServer, async_client: ApifyClientAsync +) -> None: + """The deprecated `actor_standby_*` arguments of async `create` warn at the caller and are sent as `server_*`.""" + captured: list[Request] = [] + httpserver.expect_request(_TASKS_PATH, method='POST').respond_with_handler(capture(captured)) + + with pytest.warns(DeprecationWarning, match='argument is deprecated') as record: + await async_client.tasks().create( + actor_id='test_actor_id', + name='test-task', + actor_standby_build='beta', + actor_standby_idle_timeout=timedelta(seconds=90), + ) + + assert [warning.filename for warning in record] == [__file__, __file__] + assert len(captured) == 1 + assert server_body(captured[0]) == _SERVER_EXPECTED_BODY