Skip to content

Commit 3fd00ef

Browse files
authored
Reduce sync interval to 10 secs for first hour of runtime (#11)
* Reduce sync interval to 10 secs for first hour of runtime * Fix mock for sync interval in tests
1 parent 7878413 commit 3fd00ef

File tree

6 files changed

+318
-336
lines changed

6 files changed

+318
-336
lines changed

apitally/client/asyncio.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ def __init__(
3636
client_id: str,
3737
env: str,
3838
sync_api_keys: bool = False,
39-
sync_interval: float = 60,
4039
key_cache_class: Optional[Type[ApitallyKeyCacheBase]] = None,
4140
) -> None:
4241
super().__init__(
4342
client_id=client_id,
4443
env=env,
4544
sync_api_keys=sync_api_keys,
46-
sync_interval=sync_interval,
4745
key_cache_class=key_cache_class,
4846
)
4947
self._stop_sync_loop = False

apitally/client/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
HUB_VERSION = "v1"
2424
REQUEST_TIMEOUT = 10
2525
MAX_QUEUE_TIME = 3600
26+
SYNC_INTERVAL = 60
27+
INITIAL_SYNC_INTERVAL = 10
28+
INITIAL_SYNC_INTERVAL_DURATION = 3600
2629

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

@@ -43,7 +46,6 @@ def __init__(
4346
client_id: str,
4447
env: str,
4548
sync_api_keys: bool = False,
46-
sync_interval: float = 60,
4749
key_cache_class: Optional[Type[ApitallyKeyCacheBase]] = None,
4850
) -> None:
4951
if hasattr(self, "client_id"):
@@ -58,7 +60,6 @@ def __init__(
5860
self.client_id = client_id
5961
self.env = env
6062
self.sync_api_keys = sync_api_keys
61-
self.sync_interval = sync_interval
6263
self.instance_uuid = str(uuid4())
6364
self.request_counter = RequestCounter()
6465
self.validation_error_counter = ValidationErrorCounter()
@@ -82,6 +83,12 @@ def get_instance(cls: Type[TApitallyClient]) -> TApitallyClient:
8283
raise RuntimeError("Apitally client not initialized") # pragma: no cover
8384
return cast(TApitallyClient, cls._instance)
8485

86+
@property
87+
def sync_interval(self) -> float:
88+
return (
89+
SYNC_INTERVAL if time.time() - self._started_at > INITIAL_SYNC_INTERVAL_DURATION else INITIAL_SYNC_INTERVAL
90+
)
91+
8592
@property
8693
def hub_url(self) -> str:
8794
return f"{HUB_BASE_URL}/{HUB_VERSION}/{self.client_id}/{self.env}"

apitally/client/threading.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ def __init__(
5353
client_id: str,
5454
env: str,
5555
sync_api_keys: bool = False,
56-
sync_interval: float = 60,
5756
key_cache_class: Optional[Type[ApitallyKeyCacheBase]] = None,
5857
) -> None:
5958
super().__init__(
6059
client_id=client_id,
6160
env=env,
6261
sync_api_keys=sync_api_keys,
63-
sync_interval=sync_interval,
6462
key_cache_class=key_cache_class,
6563
)
6664
self._thread: Optional[Thread] = None

0 commit comments

Comments
 (0)