Skip to content

Commit

Permalink
request registry after first failure, fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbard committed Jul 19, 2014
1 parent 2f1b57e commit 359e99e
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions extension/services/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@ define(function (require, exports, module){
_ = require('../vendor/lodash.min');

exports.getRegistry = function(){
function getRegistry(registryPathTemplate, defer, iteration){
$.ajax({
url: _.template(registryPathTemplate, {
date: new Date().getTime()
})
}).success(function(data){
defer.resolve(data);
}).error(function(jqXHR, status, error){
console.error(error);

if (iteration > 10){
defer.reject();
} else {
setTimeout(function(){
getRegistry(registryPathTemplate, defer, iteration ++);
}, 1000 * (iteration + 1));
}
});
}

var defer = q.defer(),
registryPathTemplate = 'https://s3.amazonaws.com/extend.brackets/registry.json?_=${date}';

$.ajax({
url: _.template(registryPathTemplate, {
date: new Date().getTime()
})
}).success(function(data){
defer.resolve(data);
}).error(function(){
defer.reject();
});
getRegistry(registryPathTemplate, defer, 0);

return defer.promise;
}
Expand Down

0 comments on commit 359e99e

Please sign in to comment.