Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from Financial-Times/wait-on-__gtg
Browse files Browse the repository at this point in the history
Don't exit until the app is __gtg
  • Loading branch information
matthew-andrews committed Mar 17, 2015
2 parents 3bd4183 + 61d8a48 commit 4ed1ddf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: false
language: node_js
script: npm test
node_js:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"haikro": "^1.13.0",
"heroku-client": "^1.9.1",
"fetchres": "^1.0.4",
"isomorphic-fetch": "^1.1.0"
"isomorphic-fetch": "^2.0.0"
},
"devDependencies": {
"npm-prepublish": "^1.2.0",
Expand Down
31 changes: 31 additions & 0 deletions tasks/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,36 @@ module.exports = function(app) {
project: process.cwd(),
commit: commit
});
})

// Start polling
.then(function() {
return new Promise(function(resolve, reject) {
var timeout;
var checker;
function checkGtg() {
console.log('polling: http://' + name + '.herokuapp.com/__gtg');
fetch('http://' + name + '.herokuapp.com/__gtg', {
timeout: 2000,
follow: 0
})
.then(function(response) {
if (response.ok) {
console.log("poll ok");
clearTimeout(timeout);
clearInterval(checker);
resolve();
} else {
console.log("poll not ok");
}
});
}
checker = setInterval(checkGtg, 3000);
timeout = setTimeout(function() {
console.log("2 minutes passed, bailing");
reject(name + '.herokuapp.com/__gtg not responding with an ok response within 2 minutes');
clearInterval(checker);
}, 2*60*1000);
});
});
};
9 changes: 8 additions & 1 deletion tasks/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ module.exports = function(name) {
.then(function() {
var server = {
app: name,
region: 'eu',

// The ‘app not found’ error page is hosted in the US stack
// and it seems there is a bit of latency between Heroku's
// US and EU stacks which means if you hit the app's URL
// before the US is aware of it, the DNS will point to the US
// and take a *few minutes* to expire and point to the EU.
// For simplicity, just spin these boxes up in the US.
region: 'us',
token: token,
organization: 'financial-times'
};
Expand Down

0 comments on commit 4ed1ddf

Please sign in to comment.