Skip to content

Fix infinite loop in retry logic #11

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

Merged
merged 3 commits into from
Jun 2, 2025
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
21 changes: 14 additions & 7 deletions src/obelisk/asynchronous/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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}")

Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/obelisk/asynchronous/consumer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/obelisk/asynchronous/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def send(self, dataset: str, data: List[dict],

params = {
'datasetId': dataset,
'timestampPrecision': precision,
'timestampPrecision': precision.value,
'mode': mode.value
}

Expand Down
11 changes: 7 additions & 4 deletions src/obelisk/sync/consumer_test.py
Original file line number Diff line number Diff line change
@@ -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"],
Expand All @@ -13,16 +16,16 @@ 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"],
from_timestamp=1740924034000,
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,
Expand Down