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

lib/tasks/purge-all is broken #22

Open
renoirb opened this issue May 21, 2015 · 0 comments
Open

lib/tasks/purge-all is broken #22

renoirb opened this issue May 21, 2015 · 0 comments

Comments

@renoirb
Copy link

renoirb commented May 21, 2015

I’ve had issues with the purge-all task. After some digging, its caused by superagent who makes request with 'Content-Encoding'.

Here is a refactor proposal to use the request package instead. I picked the same version as phantom uses.

diff --git c/lib/tasks/purge-all.js w/lib/tasks/purge-all.js
index 56cecd6..ed42258 100644
--- c/lib/tasks/purge-all.js
+++ w/lib/tasks/purge-all.js
@@ -1,16 +1,28 @@

-var sua = require("superagent");
+var request = require("request");

 // expects:
 //  purgeAllURL:    the URL to purge Fastly
 //  purgeAllKey:    the key for the Fastly service
 module.exports = function (ctx, cb) {
-    sua.post(ctx.purgeAllURL)
-        .set("Fastly-Key", ctx.purgeAllKey)
-        .set('Accept', 'application/json')
-        .end(function (err, res) {
-            if (!err && res.body && res.body.status === "ok") return cb();
-            cb(new Error(res.body ? res.body.status : "No response body for purge"));
-        })
-    ;
+
+    var options = {
+          url: ctx.purgeAllURL
+        , method: 'POST'
+        , headers: {
+                  'User-Agent': 'WebPlatformPublican/1'
+                , 'Fastly-Key': ctx.purgeAllKey
+        }
+    };
+
+    return request(options, function requestCallback(error, response, body) {
+        var info = JSON.parse(body);
+        if (!error && response.statusCode == 200) {
+            console.log('Purge worked', info);
+            return cb();
+        } else {
+            cb( new Error('Error purging, message ', info ) );
+        }
+    });
+
 };

In package.json;

+    "request": "2.42.0"

My concern about purge all is that its a very powerful thing to do. Maybe I should just adjust the lifetime of items to last a few minutes but set it so that it can remain "stale" for a long period.

This would do what we both want; don’t need to purge every now and then, AND keep the site up even when the servers underneath are down.

renoirb added a commit to webplatform/publican that referenced this issue May 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant