diff --git a/README.md b/README.md index 6d46eeb..c795c41 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,8 @@ The `init` function accepts the following optional configuration arguments. | ------ | ----- | ----- | ----- | | **`assignment_logger`** | [AssignmentLogger](https://github.com/Eppo-exp/python-sdk/blob/ebc1a0b781769fe9d2e2be6fc81779eb8685a6c7/eppo_client/assignment_logger.py#L6-L10) | A callback that sends each assignment to your data warehouse. Required only for experiment analysis. See [example](#assignment-logger) below. | `None` | | **`is_graceful_mode`** | bool | When true, gracefully handles all exceptions within the assignment function and returns the default value. | `True` | - +| **`poll_interval_seconds`** | int | The interval in seconds at which the SDK polls for configuration updates. | `300` | +| **`poll_jitter_seconds`** | int | The jitter in seconds to add to the poll interval. | `30` | ## Assignment logger diff --git a/eppo_client/__init__.py b/eppo_client/__init__.py index 91ee517..427ed12 100644 --- a/eppo_client/__init__.py +++ b/eppo_client/__init__.py @@ -48,6 +48,8 @@ def init(config: Config) -> EppoClient: __client = EppoClient( config_requestor=config_requestor, assignment_logger=assignment_logger, + poll_interval_seconds=config.poll_interval_seconds, + poll_jitter_seconds=config.poll_jitter_seconds, is_graceful_mode=is_graceful_mode, ) return __client diff --git a/eppo_client/client.py b/eppo_client/client.py index 4ae6f1f..c1cde48 100644 --- a/eppo_client/client.py +++ b/eppo_client/client.py @@ -14,7 +14,6 @@ from eppo_client.configuration_requestor import ( ExperimentConfigurationRequestor, ) -from eppo_client.constants import POLL_INTERVAL_MILLIS, POLL_JITTER_MILLIS from eppo_client.models import VariationType from eppo_client.poller import Poller from eppo_client.sharders import MD5Sharder @@ -22,6 +21,10 @@ from eppo_client.validation import validate_not_blank from eppo_client.eval import FlagEvaluation, Evaluator, none_result from eppo_client.version import __version__ +from eppo_client.constants import ( + POLL_INTERVAL_SECONDS_DEFAULT, + POLL_JITTER_SECONDS_DEFAULT, +) logger = logging.getLogger(__name__) @@ -33,13 +36,15 @@ def __init__( config_requestor: ExperimentConfigurationRequestor, assignment_logger: AssignmentLogger, is_graceful_mode: bool = True, + poll_interval_seconds: int = POLL_INTERVAL_SECONDS_DEFAULT, + poll_jitter_seconds: int = POLL_JITTER_SECONDS_DEFAULT, ): self.__config_requestor = config_requestor self.__assignment_logger = assignment_logger self.__is_graceful_mode = is_graceful_mode self.__poller = Poller( - interval_millis=POLL_INTERVAL_MILLIS, - jitter_millis=POLL_JITTER_MILLIS, + interval_millis=poll_interval_seconds * 1000, + jitter_millis=poll_jitter_seconds * 1000, callback=config_requestor.fetch_and_store_configurations, ) self.__poller.start() diff --git a/eppo_client/config.py b/eppo_client/config.py index d9d7d88..62e8e7d 100644 --- a/eppo_client/config.py +++ b/eppo_client/config.py @@ -1,7 +1,10 @@ from eppo_client.assignment_logger import AssignmentLogger from eppo_client.base_model import SdkBaseModel - from eppo_client.validation import validate_not_blank +from eppo_client.constants import ( + POLL_INTERVAL_SECONDS_DEFAULT, + POLL_JITTER_SECONDS_DEFAULT, +) class Config(SdkBaseModel): @@ -9,6 +12,8 @@ class Config(SdkBaseModel): base_url: str = "https://fscdn.eppo.cloud/api" assignment_logger: AssignmentLogger is_graceful_mode: bool = True + poll_interval_seconds: int = POLL_INTERVAL_SECONDS_DEFAULT + poll_jitter_seconds: int = POLL_JITTER_SECONDS_DEFAULT def _validate(self): validate_not_blank("api_key", self.api_key) diff --git a/eppo_client/constants.py b/eppo_client/constants.py index a13e8c8..e0f7f3a 100644 --- a/eppo_client/constants.py +++ b/eppo_client/constants.py @@ -1,5 +1,6 @@ # poller -SECOND_MILLIS = 1000 -MINUTE_MILLIS = 60 * SECOND_MILLIS -POLL_JITTER_MILLIS = 30 * SECOND_MILLIS -POLL_INTERVAL_MILLIS = 5 * MINUTE_MILLIS +# We accidently shipped Python with a 5 minute poll interval. +# Customers can set the poll interval to 30 seconds to match the behavior of the other server SDKs. +# Please change this to 30 seconds when ready to bump to 4.0. +POLL_JITTER_SECONDS_DEFAULT = 30 # 30 seconds +POLL_INTERVAL_SECONDS_DEFAULT = 5 * 60 # 5 minutes diff --git a/eppo_client/version.py b/eppo_client/version.py index 903a158..91b5628 100644 --- a/eppo_client/version.py +++ b/eppo_client/version.py @@ -1 +1,4 @@ -__version__ = "3.4.0" +# Note to developers: When ready to bump to 4.0, please change +# the `POLL_INTERVAL_SECONDS` constant in `eppo_client/constants.py` +# to 30 seconds to match the behavior of the other server SDKs. +__version__ = "3.5.0"