Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy purge many keys bugfix #293

Merged
merged 5 commits into from
Jul 5, 2024
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
33 changes: 18 additions & 15 deletions arxiv/integration/fastly/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ def purge_fastly_keys(key:Union[str, List[str]], service_name: Optional[str]="ar

with fastly.ApiClient(configuration) as api_client:
api_instance = PurgeApi(api_client)
try:
if isinstance(key, str):
if isinstance(key, str):
try:
api_response=_purge_single_key(key, SERVICE_IDS[service_name], api_instance, soft_purge)
logger.info(f"Fastly Purge service: {service_name}, key: {key}, status: {api_response.get('status')}, id: {api_response.get('id')}")
else:
except fastly.ApiException as e:
logger.error(f"Exception purging fastly key(s): {e} service: {service_name}, key: {key}")
else:
try:
_purge_multiple_keys(key, SERVICE_IDS[service_name], api_instance, soft_purge)
logger.info(f"Fastly bulk purge complete service: {service_name}, keys: {key}")
except fastly.ApiException as e:
logger.error(f"Exception purging fastly key(s): {e} service: {service_name}, key: {key}")
logger.info(f"Fastly bulk purge complete service: {service_name}, keys ({len(key)}): {key}")
except fastly.ApiException as e:
logger.error(f"Exception purging fastly key(s): {e} service: {service_name}, for {len(key)} keys")

def _purge_single_key(key:str, service_id: str, api_instance: PurgeApi, soft_purge: bool=False)->Any:
"""purge all pages with a specific key from fastly, fastly will not indicate if the key does not exist"""
Expand All @@ -143,13 +146,13 @@ def _purge_multiple_keys(keys: List[str], service_id:str, api_instance: PurgeApi
if len(keys)> MAX_PURGE_KEYS:
_purge_multiple_keys(keys[0:MAX_PURGE_KEYS], service_id, api_instance, soft_purge)
_purge_multiple_keys(keys[MAX_PURGE_KEYS:], service_id, api_instance,soft_purge)

options = {
'service_id': service_id,
'purge_response': {'surrogate_keys':keys,}
}
if soft_purge:
options['fastly_soft_purge']=1
api_response=api_instance.bulk_purge_tag(**options)
logger.debug(f"Bulk purge keys response: {api_response}")
else:
options = {
'service_id': service_id,
'purge_response': {'surrogate_keys':keys,}
}
if soft_purge:
options['fastly_soft_purge']=1
api_response=api_instance.bulk_purge_tag(**options)
#logger.debug(f"Bulk purge keys response: {api_response}")
return
1 change: 1 addition & 0 deletions arxiv/integration/tests/test_fastly.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_purge_over_max_keys(self, MockApiClient, MockPurgeApi: PurgeApi):
]

mock_api_instance.bulk_purge_tag.assert_has_calls(calls, any_order=True)
self.assertEqual(mock_api_instance.bulk_purge_tag.call_count, len(calls))


#tests for adding surrogate keys helper function
Expand Down
Loading