Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions charon/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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",
Expand Down
15 changes: 12 additions & 3 deletions charon/pkgs/pkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down