Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce sync interval to 10 secs for first hour of runtime #11

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apitally/client/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ def __init__(
client_id: str,
env: str,
sync_api_keys: bool = False,
sync_interval: float = 60,
key_cache_class: Optional[Type[ApitallyKeyCacheBase]] = None,
) -> None:
super().__init__(
client_id=client_id,
env=env,
sync_api_keys=sync_api_keys,
sync_interval=sync_interval,
key_cache_class=key_cache_class,
)
self._stop_sync_loop = False
Expand Down
11 changes: 9 additions & 2 deletions apitally/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
HUB_VERSION = "v1"
REQUEST_TIMEOUT = 10
MAX_QUEUE_TIME = 3600
SYNC_INTERVAL = 60
INITIAL_SYNC_INTERVAL = 10
INITIAL_SYNC_INTERVAL_DURATION = 3600

TApitallyClient = TypeVar("TApitallyClient", bound="ApitallyClientBase")

Expand All @@ -43,7 +46,6 @@ def __init__(
client_id: str,
env: str,
sync_api_keys: bool = False,
sync_interval: float = 60,
key_cache_class: Optional[Type[ApitallyKeyCacheBase]] = None,
) -> None:
if hasattr(self, "client_id"):
Expand All @@ -58,7 +60,6 @@ def __init__(
self.client_id = client_id
self.env = env
self.sync_api_keys = sync_api_keys
self.sync_interval = sync_interval
self.instance_uuid = str(uuid4())
self.request_counter = RequestCounter()
self.validation_error_counter = ValidationErrorCounter()
Expand All @@ -82,6 +83,12 @@ def get_instance(cls: Type[TApitallyClient]) -> TApitallyClient:
raise RuntimeError("Apitally client not initialized") # pragma: no cover
return cast(TApitallyClient, cls._instance)

@property
def sync_interval(self) -> float:
return (
SYNC_INTERVAL if time.time() - self._started_at > INITIAL_SYNC_INTERVAL_DURATION else INITIAL_SYNC_INTERVAL
)

@property
def hub_url(self) -> str:
return f"{HUB_BASE_URL}/{HUB_VERSION}/{self.client_id}/{self.env}"
Expand Down
2 changes: 0 additions & 2 deletions apitally/client/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ def __init__(
client_id: str,
env: str,
sync_api_keys: bool = False,
sync_interval: float = 60,
key_cache_class: Optional[Type[ApitallyKeyCacheBase]] = None,
) -> None:
super().__init__(
client_id=client_id,
env=env,
sync_api_keys=sync_api_keys,
sync_interval=sync_interval,
key_cache_class=key_cache_class,
)
self._thread: Optional[Thread] = None
Expand Down
Loading
Loading