Skip to content
Merged
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
24 changes: 19 additions & 5 deletions consul/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,19 @@ def __init__(self,
health_client: Consul.Health,
watch_seconds: str,
service: str,
passing: bool):
passing: bool,
dc: str):
super().__init__(watch_seconds)
self.service = service
self.health_client = health_client
self.passing = passing
self.dc = dc
self.index, service_health = health_client.service(
service=service,
passing=passing,
dc=dc,
)
self.cache = {self.service: service_health}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кстати, мб индекс можно и использовать вполне, чтобы запрос из кеша сразу с индексом отправлять

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кстати да) это прям очень хорошо будет. Сейчас вставлю

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Готово! Проверил, все как надо идёт)


def _update_cache(self):
while self._running:
Expand All @@ -406,7 +414,8 @@ def _update_cache(self):
'service': self.service,
'passing': self.passing,
'index': self.index,
'wait': self.watch_seconds
'wait': self.watch_seconds,
'dc': self.dc
}
log.debug(f'Param for health query: {params}')
self.index, values = self.health_client.service(**params)
Expand Down Expand Up @@ -443,18 +452,22 @@ def __init__(self,
watch_seconds: str,
path: str,
total_timeout: int,
recurse: bool,
consistency_mode: ConsistencyMode,
cache_initial_warmup_timeout=None):
super().__init__(watch_seconds)
self.kv_client = kv_client
self.path = path
self.recurse = recurse
self.consistency_mode = consistency_mode.value
self.total_timeout = total_timeout
self.cache_initial_warmup_timeout = cache_initial_warmup_timeout
self.cache = {self.path: kv_client.get(
self.index, kv = kv_client.get(
key=path,
recurse=recurse,
total_timeout=self._get_warmup_timeout()
)[1]}
)
self.cache = {self.path: kv}

def _get_warmup_timeout(self):
if self.cache_initial_warmup_timeout:
Expand All @@ -472,7 +485,8 @@ def _update_cache(self):
'index': self.index,
'wait': self.watch_seconds,
'total_timeout': self.total_timeout,
'consistency': self.consistency_mode
'consistency': self.consistency_mode,
'recurse': self.recurse
}
log.debug(f'Param for kv query: {params}')
self.index, values = self.kv_client.get(**params)
Expand Down