Skip to content

Commit

Permalink
fix for issue518
Browse files Browse the repository at this point in the history
  • Loading branch information
pooja1pathak committed Oct 11, 2023
1 parent 93e6d8c commit 2751632
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/translators/crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'))


Expand Down
14 changes: 14 additions & 0 deletions src/utils/cfgreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2751632

Please sign in to comment.