Skip to content

Commit bbe6c27

Browse files
committed
feat: add new config variables to Actor.config
1 parent 7d35b76 commit bbe6c27

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ keywords = [
4444
[tool.poetry.dependencies]
4545
python = "^3.9"
4646
apify-client = ">=1.8.1"
47-
apify-shared = ">=1.1.2"
47+
apify-shared = ">=1.2.1"
4848
crawlee = "~0.4.0"
4949
cryptography = ">=42.0.0"
5050
# TODO: relax the upper bound once the issue is resolved:

src/apify/_configuration.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from datetime import datetime, timedelta
4-
from typing import Annotated
4+
from typing import Annotated, Any
55

66
from pydantic import AliasChoices, BeforeValidator, Field
77
from typing_extensions import deprecated
@@ -13,6 +13,14 @@
1313
from apify._utils import docs_group
1414

1515

16+
def _transform_to_list(value: Any) -> list[str] | None:
17+
if value is None:
18+
return None
19+
if not value:
20+
return []
21+
return value if isinstance(value, list) else str(value).split(',')
22+
23+
1624
@docs_group('Classes')
1725
class Configuration(CrawleeConfiguration):
1826
"""A class for specifying the configuration of an Actor.
@@ -33,6 +41,13 @@ class Configuration(CrawleeConfiguration):
3341
),
3442
] = None
3543

44+
actor_full_name: Annotated[
45+
str | None,
46+
Field(
47+
description='Full name of the Actor',
48+
),
49+
] = None
50+
3651
actor_run_id: Annotated[
3752
str | None,
3853
Field(
@@ -67,6 +82,14 @@ class Configuration(CrawleeConfiguration):
6782
),
6883
] = None
6984

85+
actor_build_tags: Annotated[
86+
list[str] | None,
87+
Field(
88+
description='Build tags of the Actor build used in the run',
89+
),
90+
BeforeValidator(_transform_to_list),
91+
] = None
92+
7093
actor_task_id: Annotated[
7194
str | None,
7295
Field(
@@ -185,6 +208,15 @@ class Configuration(CrawleeConfiguration):
185208
BeforeValidator(lambda val: val or None),
186209
] = None
187210

211+
max_total_charge_usd: Annotated[
212+
float | None,
213+
Field(
214+
alias='actor_max_total_charge_usd',
215+
description='For pay-per-event Actors, the user-set limit on total charges. Do not exceed this limit',
216+
),
217+
BeforeValidator(lambda val: val or None),
218+
] = None
219+
188220
meta_origin: Annotated[
189221
str | None,
190222
Field(

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from apify_shared.consts import (
1111
BOOL_ENV_VARS,
12+
COMMA_SEPARATED_LIST_ENV_VARS,
1213
DATETIME_ENV_VARS,
1314
FLOAT_ENV_VARS,
1415
INTEGER_ENV_VARS,
@@ -108,9 +109,29 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
108109
continue
109110

110111
string_get_env_var = string_env_var.name.lower()
111-
expected_get_env[string_get_env_var] = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
112+
expected_value = ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
113+
# URLs have to be valid
114+
if string_get_env_var.endswith('url'):
115+
expected_value = f'http://example.com/{expected_value}'
116+
expected_get_env[string_get_env_var] = expected_value
112117
monkeypatch.setenv(string_env_var, expected_get_env[string_get_env_var])
113118

119+
for list_env_var in COMMA_SEPARATED_LIST_ENV_VARS:
120+
if list_env_var in ignored_env_vars:
121+
continue
122+
123+
available_values = ['val1', 'val2']
124+
125+
list_get_env_var = list_env_var.name.lower()
126+
expected_value_count = random.randint(0, len(available_values))
127+
expected_get_env[list_get_env_var] = random.sample(available_values, expected_value_count)
128+
monkeypatch.setenv(list_env_var, ','.join(expected_get_env[list_get_env_var]))
129+
130+
# Test behavior with mising env var in case of empty list
131+
if expected_value_count == 0 and random.random() < 0.5:
132+
monkeypatch.delenv(list_env_var)
133+
expected_get_env[list_get_env_var] = None
134+
114135
# We need this override so that the actor doesn't fail when connecting to the platform events websocket
115136
monkeypatch.delenv(ActorEnvVars.EVENTS_WEBSOCKET_URL)
116137
monkeypatch.delenv(ApifyEnvVars.ACTOR_EVENTS_WS_URL)

0 commit comments

Comments
 (0)