Fix #5553: Clean cache support added in topology runner (#5554)

* Fix #5553: Clean cache support added in topology runner

* used get_ctx_default
This commit is contained in:
Mayur Singal 2022-06-22 11:32:52 +05:30 committed by GitHub
parent 7685173447
commit 841bb39d3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -80,6 +80,11 @@ class TopologyRunnerMixin(Generic[C]):
except ValueError: except ValueError:
logger.error("Value unexpectedly None") logger.error("Value unexpectedly None")
# processing for all stages completed now cleaning the cache if applicable
for stage in node.stages:
if stage.clear_cache:
self.clear_context(stage=stage)
# process all children from the node being run # process all children from the node being run
yield from self.process_nodes(child_nodes) yield from self.process_nodes(child_nodes)
@ -114,6 +119,13 @@ class TopologyRunnerMixin(Generic[C]):
""" """
self.context.__dict__[key].append(value) self.context.__dict__[key].append(value)
def clear_context(self, stage: NodeStage) -> None:
"""
Clear the available context
:param key: element to update from the source context
"""
self.context.__dict__[stage.context] = get_ctx_default(stage)
def fqn_from_context(self, stage: NodeStage, entity_request: C) -> str: def fqn_from_context(self, stage: NodeStage, entity_request: C) -> str:
""" """
Read the context Read the context

View File

@ -38,6 +38,7 @@ class NodeStage(BaseModel, Generic[T]):
cache_all: bool = ( cache_all: bool = (
False # If we need to cache all values being yielded in the context False # If we need to cache all values being yielded in the context
) )
clear_cache: bool = False # If we need to clean cache values in the context for each produced element
consumer: Optional[ consumer: Optional[
List[str] List[str]
] = None # keys in the source context to fetch state from the parent's context ] = None # keys in the source context to fetch state from the parent's context

View File

@ -88,6 +88,7 @@ class DashboardServiceTopology(ServiceTopology):
consumer=["dashboard_service"], consumer=["dashboard_service"],
nullable=True, nullable=True,
cache_all=True, cache_all=True,
clear_cache=True,
), ),
NodeStage( NodeStage(
type_=CreateUserRequest, type_=CreateUserRequest,