Skip to content

Commit

Permalink
db/master: Remove dbAck
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Apr 8, 2018
1 parent c72139a commit e614f7b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
20 changes: 3 additions & 17 deletions cluster.js
Expand Up @@ -19,9 +19,6 @@ function cluster () {
return
}

let dbData = []
setInterval(() => sendDBDataUntilAck(), 10)

global.configuration = new (require('./libs/configuration.js'))()
global.currency = new (require('./libs/currency.js'))()
global.users = new (require('./libs/users.js'))()
Expand Down Expand Up @@ -54,11 +51,8 @@ function cluster () {
await message(data)
workerIsFree.message = true
break
case 'dbAck':
debug('cluster:dbAck')(data)
dbData = _.filter(dbData, (o) => o.id !== data.id)
break
case 'db':
workerIsFree.db = false
switch (data.fnc) {
case 'find':
data.items = await global.db.engine.find(data.table, data.where)
Expand All @@ -84,20 +78,12 @@ function cluster () {
default:
global.log.error('This db call is not correct\n%j', data)
}
dbData.push(data)
process.send(data)
workerIsFree.db = true
}
})
})

function sendDBDataUntilAck () {
debug('cluster:sendDBDataUntilAck:data')(dbData.length)
for (let data of dbData) {
debug('cluster:sendDBDataUntilAck')(data)
process.send(data)
}
workerIsFree.db = dbData.length === 0
}

async function message (data) {
let sender = data.sender
let message = data.message
Expand Down
1 change: 0 additions & 1 deletion libs/databases/master.js
Expand Up @@ -12,7 +12,6 @@ class IMasterController extends Interface {

cluster.on('message', (worker, message) => {
debug('db:master:incoming')(`Got data from Worker#${worker.id}\n${util.inspect(message)}`)
worker.send({ type: 'dbAck', id: message.id })
this.data[message.id] = {
items: message.items,
timestamp: _.now(),
Expand Down

0 comments on commit e614f7b

Please sign in to comment.