Skip to content

Commit

Permalink
fixup(flagd): remove merge conflict error as stated by warber
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
  • Loading branch information
aepfli committed Dec 5, 2024
1 parent 755f04c commit 3c0e9cc
Showing 1 changed file with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@ def __init__(
self.emit_provider_ready = emit_provider_ready
self.emit_provider_error = emit_provider_error
self.emit_provider_configuration_changed = emit_provider_configuration_changed
self.cache: typing.Optional[BaseCacheImpl] = (
LRUCache(maxsize=self.config.max_cache_size)
if self.config.cache_type == CacheType.LRU
else None
)
self.stub, self.channel = self._create_stub()
self.retry_backoff_seconds = config.retry_backoff_ms * 0.001
self.streamline_deadline_seconds = config.stream_deadline_ms * 0.001
self.deadline = config.deadline * 0.001
self.connected = False

self._cache: typing.Optional[BaseCacheImpl] = (
LRUCache(maxsize=self.config.max_cache_size)
if self.config.cache_type == CacheType.LRU
else None
)

def _create_stub(
self,
) -> typing.Tuple[evaluation_pb2_grpc.ServiceStub, grpc.Channel]:
Expand All @@ -74,24 +73,20 @@ def _create_stub(
options=(("grpc.keepalive_time_ms", config.keep_alive),),
)
stub = evaluation_pb2_grpc.ServiceStub(channel)

if self.cache:
self.cache.clear()

return stub, channel

def initialize(self, evaluation_context: EvaluationContext) -> None:
self.connect()
self.retry_backoff_seconds = 0.1
self.connected = False

self._cache = (
LRUCache(maxsize=self.config.max_cache_size)
if self.config.cache_type == CacheType.LRU
else None
)

def shutdown(self) -> None:
self.active = False
self.channel.close()
if self._cache:
self._cache.clear()
if self.cache:
self.cache.clear()

def connect(self) -> None:
self.active = True
Expand Down Expand Up @@ -164,9 +159,9 @@ def listen(self) -> None:
def handle_changed_flags(self, data: typing.Any) -> None:
changed_flags = list(data["flags"].keys())

if self._cache:
if self.cache:
for flag in changed_flags:
self._cache.pop(flag)
self.cache.pop(flag)

self.emit_provider_configuration_changed(ProviderEventDetails(changed_flags))

Expand Down Expand Up @@ -217,8 +212,8 @@ def _resolve( # noqa: PLR0915 C901
default_value: T,
evaluation_context: typing.Optional[EvaluationContext],
) -> FlagResolutionDetails[T]:
if self._cache is not None and flag_key in self._cache:
cached_flag: FlagResolutionDetails[T] = self._cache[flag_key]
if self.cache is not None and flag_key in self.cache:
cached_flag: FlagResolutionDetails[T] = self.cache[flag_key]
cached_flag.reason = Reason.CACHED
return cached_flag

Expand Down Expand Up @@ -280,8 +275,8 @@ def _resolve( # noqa: PLR0915 C901
variant=response.variant,
)

if response.reason == Reason.STATIC and self._cache is not None:
self._cache.insert(flag_key, result)
if response.reason == Reason.STATIC and self.cache is not None:
self.cache.insert(flag_key, result)

return result

Expand Down

0 comments on commit 3c0e9cc

Please sign in to comment.