From 2751632ee6578d2613d829fe80590fc47a82e918 Mon Sep 17 00:00:00 2001 From: pooja1pathak Date: Wed, 11 Oct 2023 10:01:29 +0000 Subject: [PATCH] fix for issue518 --- RELEASE_NOTES.md | 1 + src/translators/crate.py | 4 ++-- src/utils/cfgreader.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 19477741..09d27ea8 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -30,6 +30,7 @@ - Resolved TODO at src/reporter/tests/utils.py (#692) - Added error handling in src/wq/ql/notify.py (#673) - NGSI-LD tenant header (#664, #669) +- insert a start check to verify that crate back off factor is less than 120 and it does not conflict with WQ retry (#518) ### Bug fixes diff --git a/src/translators/crate.py b/src/translators/crate.py index 0aecc820..7c0a70f7 100644 --- a/src/translators/crate.py +++ b/src/translators/crate.py @@ -14,7 +14,7 @@ NGSI_LD_GEOMETRY, TIME_INDEX, METADATA_TABLE_NAME, FIWARE_SERVICEPATH import logging from .crate_geo_query import from_ngsi_query -from utils.cfgreader import EnvReader, StrVar, IntVar, FloatVar +from utils.cfgreader import EnvReader, StrVar, IntVar, FloatRangeVar from utils.connection_manager import ConnectionManager # CRATE TYPES @@ -68,7 +68,7 @@ def read_env(self, env: dict = os.environ): mask_value=True)) # Added backoff_factor for retry interval between attempt of # consecutive retries - self.backoff_factor = r.read(FloatVar('CRATE_BACKOFF_FACTOR', 0.0)) + self.backoff_factor = r.read(FloatRangeVar(var_name='CRATE_BACKOFF_FACTOR', default_value=0.0, lo=0.0, hi=120.0)) self.active_shards = r.read(StrVar('CRATE_WAIT_ACTIVE_SHARDS', '1')) diff --git a/src/utils/cfgreader.py b/src/utils/cfgreader.py index 7704ff82..f61a9d6a 100644 --- a/src/utils/cfgreader.py +++ b/src/utils/cfgreader.py @@ -79,6 +79,20 @@ def _do_read(self, rep: str) -> float: return float(rep) +class FloatRangeVar(EVar): + def __init__(var_name, default_value, mask_value, lo, hi): + super(var_name, default_value, mask_value) + if lo <= hi: + self.lo = lo + self.hi = hi + + def _do_read(self, rep: str) -> float: + value = float(rep) + if value not in range(self.lo, self.hi): + raise ValueError('value out of range: {}'.format(value)) + return value + + class BoolVar(EVar): """ An env value parsed as a boolean. It evaluates to true just in case the