fix: prevent unnecessary retries on last attempt in ID generation

Co-authored-by: aider (openrouter/openai/o3-mini-high) <aider@aider.chat>
This commit is contained in:
Stanislav Hejny
2025-07-15 16:55:07 +01:00
parent 7cd2960fda
commit c63941e4a1
+8 -7
View File
@@ -83,13 +83,14 @@ def get_unique_instance_id(config: AMQAdapter) -> int:
logger.debug(f"Successfully obtained unique ID: {new_value}") logger.debug(f"Successfully obtained unique ID: {new_value}")
return new_value return new_value
logger.debug(f"CAS update failed on attempt {attempt + 1}, retrying...") logger.debug(f"CAS update failed on attempt {attempt + 1}, retrying...")
time.sleep(retry_delay_seconds * (1 << attempt)) # Exponential backoff if attempt < max_retries - 1:
index, data = c.get(consul_counter_key) time.sleep(retry_delay_seconds * (1 << attempt)) # Exponential backoff
if data is None: index, data = c.get(consul_counter_key)
logger.error("Counter disappeared during update") if data is None:
return generate_fallback_id() logger.error("Counter disappeared during update")
current_value = int(data["Value"].decode("utf-8")) return generate_fallback_id()
new_value = current_value + 1 current_value = int(data["Value"].decode("utf-8"))
new_value = current_value + 1
logger.error(f"Failed to update counter after {max_retries} attempts") logger.error(f"Failed to update counter after {max_retries} attempts")
return generate_fallback_id() return generate_fallback_id()
except Exception as e: except Exception as e: