Skip to content

Commit

Permalink
introduce env param CANTAMEN_IXSI_API_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed Jan 18, 2024
1 parent df5bcdc commit d3320cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions x2gbfs/providers/api/ixsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class IxsiAPI:
def __init__(self, system_id: str, uri: str, timeout=5):
def __init__(self, system_id: str, uri: str, timeout=5, max_size=2**24):
"""
Send a message to a recipient.
Expand All @@ -16,9 +16,10 @@ def __init__(self, system_id: str, uri: str, timeout=5):
self.system_id = system_id
self.uri = uri
self.timeout = timeout
self.max_size = max_size

def _request(self, message):
with connect(self.uri) as websocket:
with connect(self.uri, max_size=self.max_size) as websocket:
websocket.send(message)
return websocket.recv(timeout=self.timeout)

Expand Down
6 changes: 5 additions & 1 deletion x2gbfs/providers/cantamen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CantamenIXSIProvider(BaseProvider):
It can be configured via ENV variables:
* CANTAMEN_IXSI_API_URL (required): an IXSIv5 service endpoint url
* CANTAMEN_IXSI_API_TIMEOUT (specified in seconds, optional, default 5)
* CANTAMEN_IXSI_RESPONSE_MAX_SIZE (specified in bytes, optional, default 2**24)
This Provider expects the config dict to provide the followig information:
* provider_id: ID of the provider to be retrieved
Expand Down Expand Up @@ -84,12 +85,15 @@ class CantamenIXSIProvider(BaseProvider):
def __init__(self, feed_config):
self.api_url = config('CANTAMEN_IXSI_API_URL')
self.api_timeout = config('CANTAMEN_IXSI_API_TIMEOUT', 5)
self.api_response_max_size = config('CANTAMEN_IXSI_RESPONSE_MAX_SIZE', 2**24)
self.config = feed_config

def _load_response(self) -> Dict[str, Any]:
if not self.cached_response:
provider_id = self.config['provider_id']
data = IxsiAPI(self.config['system_id'], self.api_url, self.api_timeout).result_for_provider(provider_id)
data = IxsiAPI(
self.config['system_id'], self.api_url, self.api_timeout, self.api_response_max_size
).result_for_provider(provider_id)
base_data = xmltodict.parse(data)['Ixsi']['Response']['BaseData']
self._parse_attributes(base_data['Attributes'])
self.cached_response = base_data
Expand Down

0 comments on commit d3320cc

Please sign in to comment.