mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
implement nginx-like logic to avoid hitting upstream when it's down
This commit is contained in:
parent
6b9001ef6c
commit
f1ec18dc4b
1 changed files with 15 additions and 13 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue