summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2013-07-04 12:39:29 -0400
committerDonald Stufft <donald@stufft.io>2013-07-04 12:39:29 -0400
commita06239543b8a283218592bb09c3ff7628bf9e825 (patch)
tree8d2603d01cd1f8d873c93ab766f3ec06172a7dbe
parent1d431dd88c0e5a25794ff1814b42eab95a0962a7 (diff)
downloaddecorator-a06239543b8a283218592bb09c3ff7628bf9e825.tar.gz
Be more rboust about how we handle purge errors
-rw-r--r--store.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/store.py b/store.py
index 20f6a65..ba02c2a 100644
--- a/store.py
+++ b/store.py
@@ -2346,14 +2346,29 @@ class Store:
def _invalidate_cache(self):
# Purge all tags from Fastly
if self.config.fastly_api_key:
+ api_domain = self.config.fastly_api_domain
session = requests.session()
- for url in set(self._changed_urls):
- resp = session.request("PURGE", url, headers={
- "X-Fastly-Key": self.config.fastly_api_key,
- "Accept": "application/json",
- })
- resp.raise_for_status()
- self._changed_urls.remove(url)
+
+ count = 0
+ while self._changed_urls and count <= 10:
+ count += 1
+ purges = {}
+
+ for url in set(self._changed_urls):
+ # Issue the purge
+ resp = session.request("PURGE", url, headers={
+ "X-Fastly-Key": self.config.fastly_api_key,
+ "Accept": "application/json",
+ })
+ resp.raise_for_status()
+ purges[url] = resp.json()["id"]
+
+ for url, pid in purges.iteritems():
+ # Ensure that the purge completed successfully
+ status = session.get("%spurge?id=%s" % (api_domain, pid))
+ status.raise_for_status()
+ if status.json().get("results", {}).get("complete", None):
+ self._changed_urls.remove(url)
else:
self._changed_urls = set()