-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from arXiv/fastly-purge
Fastly purge
- Loading branch information
Showing
3 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
from flask import current_app | ||
|
||
def fastly_purge_abs (paper_id: str, version: int, fastly_key: str): | ||
headers = { | ||
"Fastly-Key": fastly_key, | ||
"Accept": "application/json", | ||
} | ||
domains = ["arxiv.org", "web3.arxiv.org", "www.arxiv.org"] | ||
|
||
for domain in domains: | ||
url = f"https://{ domain }/abs/{ paper_id }" | ||
|
||
response = requests.request("PURGE", url, headers=headers) | ||
|
||
if response.status_code == 200: | ||
success.append(url) | ||
else: | ||
status_code = 500 | ||
msg = 'Error purging' | ||
failed.append(url) | ||
|
||
url = f"https://{ domain }/abs/{ paper_id }v{ version }" | ||
|
||
response = requests.request("PURGE", url, headers=headers) | ||
|
||
if response.status_code == 200: | ||
logging.info(f'successfully purged { url }') | ||
else: | ||
logging.warning(f'failed to purge { url }') |