Skip to content

Commit 860f1f6

Browse files
committed
package-indexer: added option to flush CDN cache only.
Signed-off-by: Tamas Pal <[email protected]>
1 parent 39678b4 commit 860f1f6

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

packaging/package-indexer/cdn/azure_cdn.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,24 @@ def from_config(cfg: dict) -> CDN:
9595
tenant_id=cfg["tenant-id"],
9696
client_id=cfg["client-id"],
9797
client_secret=cfg["client-secret"],
98-
domains=cfg["domains"]
98+
domains=cfg["domains"],
9999
)
100100

101101
def refresh_cache(self, path: Path) -> None:
102102
path_str = str(Path("/", path))
103103

104-
self._log_info("Refreshing CDN cache.", path=path_str, domains=self.__domains)
104+
self._log_info("Refreshing CDN cache.", path=path_str, domains=str(self.__domains))
105105

106106
poller: LROPoller = self.__cdn.afd_endpoints.begin_purge_content(
107107
resource_group_name=self.__resource_group_name,
108108
profile_name=self.__profile_name,
109109
endpoint_name=self.__endpoint_name,
110-
contents={'contentPaths': [path_str], "domains": self.__domains},
110+
contents={"contentPaths": [path_str], "domains": self.__domains},
111111
)
112112
poller.wait()
113113

114114
status = poller.status()
115115
if not status == "Succeeded":
116116
raise Exception("Failed to refresh CDN cache. status: {}".format(status))
117117

118-
self._log_info("Successfully refreshed CDN cache.", path=path_str, domains=self.__domains)
118+
self._log_info("Successfully refreshed CDN cache.", path=path_str, domains=str(self.__domains))

packaging/package-indexer/index-packages.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def add_optional_arguments(parser: ArgumentParser) -> None:
7373
type=str,
7474
help="Also log more verbosely into this file.",
7575
)
76+
parser.add_argument(
77+
"--flush-cache-only",
78+
action="store_true",
79+
help="Only flush the caches of the Azure CDN. Used for testing that part.",
80+
)
7681

7782

7883
def parse_args() -> dict:
@@ -157,8 +162,12 @@ def main() -> None:
157162
cfg = load_config(args)
158163

159164
indexers = construct_indexers(cfg, args)
160-
for indexer in indexers:
161-
indexer.index()
165+
if args["flush_cache_only"]:
166+
for indexer in indexers:
167+
indexer.flush_cdn_cache()
168+
else:
169+
for indexer in indexers:
170+
indexer.index()
162171

163172

164173
if __name__ == "__main__":

packaging/package-indexer/indexer/indexer.py

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ def index(self) -> None:
8686
self.__sync_to_remote()
8787
self.__refresh_cdn_cache()
8888

89+
def flush_cdn_cache(self) -> None:
90+
self.__refresh_cdn_cache()
91+
8992
@staticmethod
9093
def __create_logger() -> logging.Logger:
9194
logger = logging.getLogger("Indexer")

0 commit comments

Comments
 (0)