summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2013-07-25 16:59:11 -0400
committerDonald Stufft <donald@stufft.io>2013-07-25 16:59:11 -0400
commit1e70ddf0ae9dfd207e216632d794237870ec97e5 (patch)
tree10363c972746669fd519d3887e6a7c5e42a23e99
parentf1a12f375bfa49ef375ab95cc3f801e2a493bd1c (diff)
downloaddecorator-1e70ddf0ae9dfd207e216632d794237870ec97e5.tar.gz
Simplify the purge API and only hit it once
-rw-r--r--tasks.py55
1 files changed, 23 insertions, 32 deletions
diff --git a/tasks.py b/tasks.py
index 8cc5d98..4a5a0dc 100644
--- a/tasks.py
+++ b/tasks.py
@@ -3,41 +3,32 @@ import urlparse
import requests
-def purge_fastly_tags(domain, api_key, service_id, tags, max_tries=25):
+def purge_fastly_tags(domain, api_key, service_id, tags):
session = requests.session()
headers = {"X-Fastly-Key": api_key, "Accept": "application/json"}
all_tags = set(tags)
purges = {}
- count = 0
-
- while all_tags and not count > max_tries:
- count += 1
-
- try:
- for tag in set(all_tags):
- # Build the URL
- url_path = "/service/%s/purge/%s" % (service_id, tag)
- url = urlparse.urljoin(domain, url_path)
-
- # Issue the Purge
- resp = session.post(url, headers=headers)
- resp.raise_for_status()
-
- # Store the Purge ID so we can track it later
- purges[tag] = resp.json()["id"]
-
- # for tag, purge_id in purges.iteritems():
- # # Ensure that the purge completed successfully
- # url = urlparse.urljoin(domain, "/purge")
- # status = session.get(url, params={"id": purge_id})
- # status.raise_for_status()
-
- # # If the purge completely successfully remove the tag from
- # # our list.
- # if status.json().get("results", {}).get("complete", None):
- # all_tags.remove(tag)
- except Exception:
- if count > max_tries:
- raise
+ for tag in set(all_tags):
+ # Build the URL
+ url_path = "/service/%s/purge/%s" % (service_id, tag)
+ url = urlparse.urljoin(domain, url_path)
+
+ # Issue the Purge
+ resp = session.post(url, headers=headers)
+ resp.raise_for_status()
+
+ # Store the Purge ID so we can track it later
+ purges[tag] = resp.json()["id"]
+
+ # for tag, purge_id in purges.iteritems():
+ # # Ensure that the purge completed successfully
+ # url = urlparse.urljoin(domain, "/purge")
+ # status = session.get(url, params={"id": purge_id})
+ # status.raise_for_status()
+
+ # # If the purge completely successfully remove the tag from
+ # # our list.
+ # if status.json().get("results", {}).get("complete", None):
+ # all_tags.remove(tag)