diff --git a/src/obelisk/asynchronous/client.py b/src/obelisk/asynchronous/client.py index 96f71b3..a0d7aa3 100644 --- a/src/obelisk/asynchronous/client.py +++ b/src/obelisk/asynchronous/client.py @@ -5,7 +5,7 @@ import httpx -from obelisk.exceptions import AuthenticationError +from obelisk.exceptions import AuthenticationError, ObeliskError from obelisk.strategies.retry import RetryStrategy, \ NoRetryStrategy from obelisk.types import ObeliskKind @@ -76,9 +76,10 @@ async def _get_token(self): async with httpx.AsyncClient() as client: response = None + request = None last_error = None retry = self.retry_strategy.make() - while not response or await retry.should_retry(): + while not response: try: request = await client.post( self._token_url, @@ -90,10 +91,13 @@ async def _get_token(self): except Exception as e: last_error = e self.log.error(e) - continue + if await retry.should_retry(): + continue + else: + break - if response is None and last_error is not None: - raise last_error + if not response or not request: + raise (last_error if last_error is not None else ObeliskError("No response")) if request.status_code != 200: if 'error' in response: @@ -142,7 +146,7 @@ async def http_post(self, url: str, data: Any = None, response = None retry = self.retry_strategy.make() last_error = None - while not response or await retry.should_retry(): + while not response: if response is not None: self.log.debug(f"Retrying, last response: {response.status_code}") @@ -158,7 +162,10 @@ async def http_post(self, url: str, data: Any = None, except Exception as e: self.log.error(e) last_error = e - continue + if await retry.should_retry(): + continue + else: + break if not response and last_error: raise last_error diff --git a/src/obelisk/asynchronous/consumer_test.py b/src/obelisk/asynchronous/consumer_test.py index 7bd04f2..7348792 100644 --- a/src/obelisk/asynchronous/consumer_test.py +++ b/src/obelisk/asynchronous/consumer_test.py @@ -3,9 +3,12 @@ pytest_plugins = ('pytest_asyncio',) +client_id = "682c6c46604b3b3be35429df" +client_secret = "7136832d-01be-456a-a1fe-25c7f9e130c5" + @pytest.mark.asyncio async def test_demo_igent(): - consumer = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") + consumer = Consumer(client=client_id, secret=client_secret) result = await consumer.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], diff --git a/src/obelisk/asynchronous/producer.py b/src/obelisk/asynchronous/producer.py index b0ad4f9..697b217 100644 --- a/src/obelisk/asynchronous/producer.py +++ b/src/obelisk/asynchronous/producer.py @@ -41,7 +41,7 @@ async def send(self, dataset: str, data: List[dict], params = { 'datasetId': dataset, - 'timestampPrecision': precision, + 'timestampPrecision': precision.value, 'mode': mode.value } diff --git a/src/obelisk/sync/consumer_test.py b/src/obelisk/sync/consumer_test.py index ca6d308..f053cfb 100644 --- a/src/obelisk/sync/consumer_test.py +++ b/src/obelisk/sync/consumer_test.py @@ -1,7 +1,10 @@ from .consumer import Consumer +client_id = "682c6c46604b3b3be35429df" +client_secret = "7136832d-01be-456a-a1fe-25c7f9e130c5" + def test_demo_igent(): - consumer = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") + consumer = Consumer(client=client_id,secret=client_secret) result = consumer.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], @@ -13,8 +16,8 @@ def test_demo_igent(): assert len(result.items) == 2 def test_two_instances(): - consumer_one = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") - consumer_two = Consumer(client="67c716e616c11421cfe2faf6", secret="08dafe89-0389-45b4-9832-cc565fb8c2eb") + consumer_one = Consumer(client=client_id,secret=client_secret) + consumer_two = Consumer(client=client_id,secret=client_secret) result_one = consumer_one.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], @@ -22,7 +25,7 @@ def test_two_instances(): to_timestamp=1741100614258, limit=2 ) - result_two = consumer_one.single_chunk( + result_two = consumer_two.single_chunk( datasets=["612f6c39cbceda0ea9753d95"], metrics=["org.dyamand.types.common.Temperature::number"], from_timestamp=1740924034000,