-
Notifications
You must be signed in to change notification settings - Fork 36
feat: fetch timeout made configurable #411
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
Changes from 15 commits
d68bec0
7c9a7ca
c23b314
da97899
6e5c853
7ff3e3d
5b1951a
4c8ad4c
8ad739f
535ba82
db878c7
75f08ca
c83c966
32618ed
48bcbe3
7546a40
1c0778d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,14 @@ | |
class OdpEventApiManager: | ||
"""Provides an internal service for ODP event REST api access.""" | ||
|
||
def __init__(self, logger: Optional[optimizely_logger.Logger] = None): | ||
def __init__(self, logger: Optional[optimizely_logger.Logger] = None, timeout: Optional[int] = None): | ||
self.logger = logger or optimizely_logger.NoOpLogger() | ||
self.timeout = timeout | ||
|
||
def send_odp_events(self, api_key: str, api_host: str, events: list[OdpEvent]) -> bool: | ||
def send_odp_events(self, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about passing the timeout value when initializing? We do not need to send timeout for every event. It's not expected we need event-by-event control. Also a custom OdpEventApiManager can have own timeout control. |
||
api_key: str, | ||
api_host: str, | ||
events: list[OdpEvent]) -> bool: | ||
""" | ||
Dispatch the event being represented by the OdpEvent object. | ||
|
||
|
@@ -69,7 +73,7 @@ def send_odp_events(self, api_key: str, api_host: str, events: list[OdpEvent]) - | |
response = requests.post(url=url, | ||
headers=request_headers, | ||
data=payload_dict, | ||
timeout=OdpEventApiConfig.REQUEST_TIMEOUT) | ||
timeout=self.timeout or OdpEventApiConfig.REQUEST_TIMEOUT) | ||
|
||
response.raise_for_status() | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -108,8 +108,9 @@ | |||||
class OdpSegmentApiManager: | ||||||
"""Interface for manging the fetching of audience segments.""" | ||||||
|
||||||
def __init__(self, logger: Optional[optimizely_logger.Logger] = None): | ||||||
def __init__(self, logger: Optional[optimizely_logger.Logger] = None, timeout: Optional[int] = None): | ||||||
self.logger = logger or optimizely_logger.NoOpLogger() | ||||||
self.timeout = timeout | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
def fetch_segments(self, api_key: str, api_host: str, user_key: str, | ||||||
user_value: str, segments_to_check: list[str]) -> Optional[list[str]]: | ||||||
|
@@ -151,7 +152,7 @@ def fetch_segments(self, api_key: str, api_host: str, user_key: str, | |||||
response = requests.post(url=url, | ||||||
headers=request_headers, | ||||||
data=payload_dict, | ||||||
timeout=OdpSegmentApiConfig.REQUEST_TIMEOUT) | ||||||
timeout=self.timeout or OdpSegmentApiConfig.REQUEST_TIMEOUT) | ||||||
|
||||||
response.raise_for_status() | ||||||
response_dict = response.json() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well just do this once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1