diff --git a/lib/up-storage.js b/lib/up-storage.js index 598628dd0..4a9e484e6 100644 --- a/lib/up-storage.js +++ b/lib/up-storage.js @@ -15,7 +15,7 @@ var URL = require('url') function Storage(config, mainconfig) { if (!(this instanceof Storage)) return new Storage(config) this.config = config - this.is_alive = true + this.failed_requests = 0 this.userAgent = mainconfig.user_agent this.ca = config.ca this.logger = Logger.logger.child({sub: 'out'}) @@ -178,22 +178,24 @@ Storage.prototype.request = function(options, cb) { Storage.prototype.status_check = function(alive) { if (arguments.length === 0) { - return true // hold off this feature until v0.6.0 - -/* if (!this.is_alive && Math.abs(Date.now() - this.is_alive_time) < 2*60*1000) { + if (this.failed_requests >= this.max_fails && Math.abs(Date.now() - this.last_request_time) < this.fail_timeout) { return false } else { return true - }*/ - } else { - if (this.is_alive && !alive) { - this.logger.warn({host: this.url.host}, 'host @{host} is now offline') - } else if (!this.is_alive && alive) { - this.logger.info({host: this.url.host}, 'host @{host} is back online') } - - this.is_alive = alive - this.is_alive_time = Date.now() + } else { + if (alive) { + if (this.failed_requests >= this.max_fails) { + this.logger.warn({host: this.url.host}, 'host @{host} is back online') + } + this.failed_requests = 0 + } else { + this.failed_requests++ + if (this.failed_requests === this.max_fails) { + this.logger.warn({host: this.url.host}, 'host @{host} is now offline') + } + } + this.last_request_time = Date.now() } }