From fbe8af7d5c65d352cd517bd14919f0f804f99327 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Thu, 11 Apr 2024 20:18:36 +0800 Subject: [PATCH] Add progress counting for CF requests processing --- charon/cache.py | 16 ++++++++++++++-- charon/pkgs/pkg_utils.py | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/charon/cache.py b/charon/cache.py index 5dd103d4..45a57751 100644 --- a/charon/cache.py +++ b/charon/cache.py @@ -86,16 +86,23 @@ def invalidate_paths( The default value is 3000 which is the maximum number in official doc: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html#InvalidationLimits """ + INPRO_W_SECS = 5 + NEXT_W_SECS = 1 real_paths = [paths] # Split paths into batches by batch_size if batch_size: real_paths = [paths[i:i + batch_size] for i in range(0, len(paths), batch_size)] + total_time_approx = len(real_paths) * (INPRO_W_SECS * 2 + NEXT_W_SECS) + logger.info("There will be %d invalidating requests in total," + " will take more than %d seconds", + len(real_paths), total_time_approx) results = [] current_invalidation = {} + processed_count = 0 for batch_paths in real_paths: while (current_invalidation and INVALIDATION_STATUS_INPROGRESS == current_invalidation.get('Status', '')): - time.sleep(5) + time.sleep(INPRO_W_SECS) try: result = self.check_invalidation(distr_id, current_invalidation.get('Id')) if result: @@ -113,9 +120,14 @@ def invalidate_paths( break if current_invalidation: results.append(current_invalidation) + processed_count += 1 + if processed_count % 10 == 0: + logger.info( + "[CloudFront] ######### %d/%d requests finished", + processed_count, len(real_paths)) # To avoid conflict rushing request, we can wait 1s here # for next invalidation request sending. - time.sleep(1) + time.sleep(NEXT_W_SECS) caller_ref = str(uuid.uuid4()) logger.debug( "Processing invalidation for batch with ref %s, size: %s", diff --git a/charon/pkgs/pkg_utils.py b/charon/pkgs/pkg_utils.py index 7d9cabc7..c340236e 100644 --- a/charon/pkgs/pkg_utils.py +++ b/charon/pkgs/pkg_utils.py @@ -2,7 +2,8 @@ from charon.cache import ( CFClient, INVALIDATION_BATCH_DEFAULT, - INVALIDATION_BATCH_WILDCARD + INVALIDATION_BATCH_WILDCARD, + INVALIDATION_STATUS_COMPLETED ) import logging import os @@ -110,9 +111,17 @@ def invalidate_cf_paths( if status not in output: output[status] = [] output[status].append(invalidation["Id"]) + non_completed = {} + for status, ids in output.items(): + if status != INVALIDATION_STATUS_COMPLETED: + non_completed[status] = ids logger.info( - "The CF invalidating request for metadata/indexing is sent, " - "request result as below:\n %s", output + "The CF invalidating requests done, these following requests " + "are not completed yet:\n %s\nPlease use cf-check command to " + "check its details.", non_completed + ) + logger.debug( + "All invalidations requested in this process:\n %s", output ) else: logger.error(