Commit db7af2a0 authored by Robert Knight's avatar Robert Knight

Merge pull request #2612 from hypothesis/exponential-backoff-features

Don't endlessly re-request features on connectivity issues
parents 68b3c4fd d0d19355
......@@ -21,28 +21,38 @@
*/
'use strict';
var retry = require('retry');
var CACHE_TTL = 5 * 60 * 1000; // 5 minutes
function features ($document, $http, $log) {
var cache = null;
var pending = false;
var operation = null;
var featuresUrl = new URL('/app/features', $document.prop('baseURI')).href;
function fetch() {
// Short-circuit if a fetch is already in progress...
if (pending) {
if (operation) {
return;
}
pending = true;
$http.get(featuresUrl)
.success(function(data) {
operation = retry.operation({retries: 10, randomize: true});
function success(data) {
cache = [Date.now(), data];
})
.error(function() {
$log.warn('features service: failed to load features data');
})
.finally(function() {
pending = false;
operation = null;
}
function failure(data, status) {
if (!operation.retry('failed to load - remote status was ' + status)) {
// All retries have failed, and we will now stop polling the endpoint.
$log.error('features service:', operation.mainError());
}
}
operation.attempt(function () {
$http.get(featuresUrl)
.success(success)
.error(failure);
});
}
......
......@@ -42,6 +42,7 @@
"node-uuid": "^1.4.3",
"postcss": "^5.0.6",
"raf": "^3.1.0",
"retry": "^0.8.0",
"scroll-into-view": "^1.3.1",
"showdown": "^1.2.1",
"uglify-js": "^2.4.14",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment