Server: do not make friends with myself
This commit is contained in:
parent
43666d616d
commit
2c49ca42d1
1 changed files with 18 additions and 2 deletions
|
@ -6,6 +6,7 @@ const eachSeries = require('async/eachSeries')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const mongoose = require('mongoose')
|
const mongoose = require('mongoose')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
const urlUtil = require('url')
|
||||||
const waterfall = require('async/waterfall')
|
const waterfall = require('async/waterfall')
|
||||||
|
|
||||||
const constants = require('../initializers/constants')
|
const constants = require('../initializers/constants')
|
||||||
|
@ -173,8 +174,11 @@ function computeWinningPods (urls, podsScore) {
|
||||||
// Only add a pod if it exists in more than a half base pods
|
// Only add a pod if it exists in more than a half base pods
|
||||||
const podsList = []
|
const podsList = []
|
||||||
const baseScore = urls.length / 2
|
const baseScore = urls.length / 2
|
||||||
Object.keys(podsScore).forEach(function (pod) {
|
Object.keys(podsScore).forEach(function (podUrl) {
|
||||||
if (podsScore[pod] > baseScore) podsList.push({ url: pod })
|
// If the pod is not me and with a good score we add it
|
||||||
|
if (isMe(podUrl) === false && podsScore[podUrl] > baseScore) {
|
||||||
|
podsList.push({ url: podUrl })
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return podsList
|
return podsList
|
||||||
|
@ -262,3 +266,15 @@ function createRequest (type, data, to) {
|
||||||
if (err) logger.error('Cannot save the request.', { error: err })
|
if (err) logger.error('Cannot save the request.', { error: err })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMe (url) {
|
||||||
|
const parsedUrl = urlUtil.parse(url)
|
||||||
|
|
||||||
|
const hostname = parsedUrl.hostname
|
||||||
|
const port = parseInt(parsedUrl.port)
|
||||||
|
|
||||||
|
const myHostname = constants.CONFIG.WEBSERVER.HOST
|
||||||
|
const myPort = constants.CONFIG.WEBSERVER.PORT
|
||||||
|
|
||||||
|
return hostname === myHostname && port === myPort
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue