shared-store
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -0,1 +1,5 @@ | ||
1.0.8 | ||
----- | ||
* retry upon failure - @chkhoo #14 | ||
1.0.7 | ||
@@ -2,0 +6,0 @@ ----- |
@@ -101,3 +101,4 @@ // Generated by CoffeeScript 1.9.0 | ||
time: time, | ||
source: absolute | ||
source: absolute, | ||
usingCache: true | ||
}; | ||
@@ -156,6 +157,9 @@ }); | ||
activeLoader = function(meta, loader, tmpDir) { | ||
var cachedData, data, fromCache, insurance, rawData; | ||
rawData = meta.flatMapLatest(loader); | ||
insurance = crashRecovery(tmpDir); | ||
data = rawData.tap(insurance.onDataLoaded).publish(); | ||
var cachedData, data, fromCache, onDataLoaded, rawData, tearDownCrashHandler, _ref1; | ||
rawData = meta.flatMapLatest(loader).map(function(data) { | ||
data.usingCache = false; | ||
return data; | ||
}); | ||
_ref1 = crashRecovery(tmpDir), onDataLoaded = _ref1.onDataLoaded, tearDownCrashHandler = _ref1.tearDownCrashHandler; | ||
data = rawData.tap(onDataLoaded, tearDownCrashHandler, tearDownCrashHandler).publish(); | ||
fromCache = tryCache(tmpDir); | ||
@@ -162,0 +166,0 @@ data.connect(); |
@@ -42,3 +42,3 @@ // Generated by CoffeeScript 1.9.0 | ||
crashRecovery = function(tmpDir) { | ||
var onApplicationCrashed, tearDownCrashHandler; | ||
var onApplicationCrashed, onDataLoaded, tearDownCrashHandler; | ||
onApplicationCrashed = function(exitCode) { | ||
@@ -79,6 +79,8 @@ var err, files; | ||
}; | ||
onDataLoaded = function() { | ||
return setTimeout(tearDownCrashHandler, 5000); | ||
}; | ||
return { | ||
onDataLoaded: function() { | ||
return setTimeout(tearDownCrashHandler, 5000); | ||
} | ||
onDataLoaded: onDataLoaded, | ||
tearDownCrashHandler: tearDownCrashHandler | ||
}; | ||
@@ -85,0 +87,0 @@ }; |
@@ -35,3 +35,3 @@ // Generated by CoffeeScript 1.9.0 | ||
'use strict'; | ||
var EventEmitter, Observable, Promise, SharedStore, cachedLoader, cluster, freeze, path, property, safeMerge, | ||
var EventEmitter, Observable, Promise, RETRY_MULTIPLIER, SharedStore, TEN_MINUTES, TEN_SECONDS, cachedLoader, cluster, freeze, path, property, safeMerge, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -59,2 +59,8 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
RETRY_MULTIPLIER = 2; | ||
TEN_SECONDS = 1000 * 10; | ||
TEN_MINUTES = 1000 * 60 * 10; | ||
SharedStore = (function(_super) { | ||
@@ -64,4 +70,6 @@ __extends(SharedStore, _super); | ||
function SharedStore(_arg) { | ||
var active, loader, meta, temp; | ||
var active, loader, temp; | ||
loader = _arg.loader, temp = _arg.temp, active = _arg.active; | ||
this._retry = __bind(this._retry, this); | ||
this._handleMetaUpdate = __bind(this._handleMetaUpdate, this); | ||
this._handleUpdate = __bind(this._handleUpdate, this); | ||
@@ -74,13 +82,17 @@ this._handleError = __bind(this._handleError, this); | ||
temp = path.resolve(temp); | ||
meta = Observable.create((function(_this) { | ||
return function(observer) { | ||
return _this.on('meta', function(value) { | ||
return observer.onNext(value); | ||
}); | ||
this._createStream = (function(_this) { | ||
return function() { | ||
var meta, _ref; | ||
if ((_ref = _this.subscription) != null) { | ||
_ref.dispose(); | ||
} | ||
meta = _this._createMeta(); | ||
_this.stream = cachedLoader(meta, loader, temp, active); | ||
return _this.subscription = _this.stream.subscribe(_this._handleUpdate, _this._handleError); | ||
}; | ||
})(this)); | ||
this.stream = cachedLoader(meta, loader, temp, active, this.emit.bind(this, 'error')); | ||
this._receivedData = false; | ||
this.stream.subscribe(this._handleUpdate, this._handleError); | ||
})(this); | ||
this._createStream(); | ||
this.on('meta', this._handleMetaUpdate); | ||
this._cache = null; | ||
this._retryTimeout = TEN_SECONDS; | ||
} | ||
@@ -117,13 +129,25 @@ | ||
SharedStore.prototype._createMeta = function() { | ||
this._metaObserver = null; | ||
return Observable.create((function(_this) { | ||
return function(observer) { | ||
if (_this._options != null) { | ||
observer.onNext(_this._options); | ||
} | ||
return _this._metaObserver = observer; | ||
}; | ||
})(this)); | ||
}; | ||
SharedStore.prototype._handleError = function(err) { | ||
if (!this._receivedData) { | ||
return; | ||
} | ||
return this.emit('error', err); | ||
this.emit('err', err); | ||
return setTimeout(this._retry, this._retryTimeout); | ||
}; | ||
SharedStore.prototype._handleUpdate = function(_arg) { | ||
var data, source, time, _ref; | ||
data = _arg.data, time = _arg.time, source = _arg.source; | ||
this._receivedData = true; | ||
var data, source, time, usingCache, _ref; | ||
data = _arg.data, time = _arg.time, source = _arg.source, usingCache = _arg.usingCache; | ||
if (usingCache === false) { | ||
this._retryTimeout = TEN_SECONDS; | ||
} | ||
this._cache = freeze({ | ||
@@ -141,2 +165,17 @@ data: data, | ||
SharedStore.prototype._handleMetaUpdate = function(_at__options) { | ||
var _ref; | ||
this._options = _at__options; | ||
return (_ref = this._metaObserver) != null ? _ref.onNext(this._options) : void 0; | ||
}; | ||
SharedStore.prototype._retry = function() { | ||
this._createStream(); | ||
this.emit('meta', this.options); | ||
this._retryTimeout *= RETRY_MULTIPLIER; | ||
if (this._retryTimeout > TEN_MINUTES) { | ||
return this._retryTimeout = TEN_MINUTES; | ||
} | ||
}; | ||
return SharedStore; | ||
@@ -143,0 +182,0 @@ |
{ | ||
"name": "shared-store", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Keeping config data in sync", | ||
@@ -5,0 +5,0 @@ "main": "lib/shared-store.js", |
@@ -189,2 +189,12 @@ # shared-store | ||
## Events | ||
Events are emitted on instances of the `SharedStore` class. Most notably, | ||
error events are emitted as `'err'` and not `'error'`. This is because | ||
unhandled `'error'` events throw, which isn't necessary when fetching fails | ||
due to HTTP connection timeouts, etc. | ||
In this scenario, the cached copy will continue to be used until the data | ||
source is available again. | ||
## Tests | ||
@@ -191,0 +201,0 @@ Once you've cloned the repository, you can run: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96625
43
1104
242