Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Satterwhite committed Apr 26, 2020
1 parent 33ffec6 commit 01bc11d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/skyring/lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Server extends http.Server {
return m.status === 'alive'
})

if(active.length) {
if (active.length) {
return this._timers.shutdown(() => {
debug('closing server');
this.closed = true;
Expand Down
17 changes: 10 additions & 7 deletions packages/skyring/lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class Timer extends Map {

}

get id() {
return this[kNode]
}

/**
* Sets a new time instance. If The timer has lapsed, it will be executed immediately
* @method module:skyring/lib/timer#create
Expand Down Expand Up @@ -321,13 +325,14 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)

if(!size) return

rebalance('node %s begin rebalance; timers: %d', this[kNode], size)
this.nats.publish('skyring:node', JSON.stringify({
node: this[kNode]
, type: EVENT_STATUS.REBALANCE
}), noop)

const records = this.values()

const records = this.values()
const run = ( obj ) => {
if (node.owns(obj.id)) return

Expand All @@ -340,7 +345,7 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)
, created: obj.created
})

rebalance( 'no longer the owner of %s', obj.id )
rebalance('node %s no longer the owner of %s', this[kNode], obj.id)

this.nats.publish('skyring:events', JSON.stringify({
node: this[kNode]
Expand All @@ -356,7 +361,7 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)
}

batch.write(() => {
store('rebalance batch delete complete')
store('node %s rebalance batch delete complete', this[kNode])
})
}

Expand Down Expand Up @@ -443,8 +448,6 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)
**/
shutdown(cb) {
const size = this.size
const client = this.nats

if (!size) {
this[storage].close()
return this.transports[shutdown](() => {
Expand All @@ -464,7 +467,7 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)

const batch = this[storage].batch()

client.unsubscribe(this._sid)
this.nats.unsubscribe(this._sid)
this._sid = null

const run = (obj) => {
Expand All @@ -473,7 +476,7 @@ timers.failure('2e2f6dad-9678-4caf-bc41-8e62ca07d551', error)
const data = Object.assign({}, obj.payload, {
id: obj.id
, created: obj.created
, count: ++sent
, count: ++senst
})

this.nats.publish('skyring', JSON.stringify(data), () => {
Expand Down
88 changes: 73 additions & 15 deletions packages/skyring/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/skyring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"leveldown": "^5.0.1",
"levelup": "^4.0.1",
"memdown": "^4.0.0",
"nats": "^1.2.10",
"nats": "^1.4.8",
"path-to-regexp": "^3.0.0",
"request": "^2.88.0",
"seeli": "^8.1.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/skyring/test/unit/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ test('server', async (t) => {
// start server 4
sfour.listen(0, () => {
// drop server 3
setImmediate(() => {
setTimeout(() => {
sthree.close(() => {
ttt.pass('server closed')
})
})
}, 200)
})
}
)
Expand Down

0 comments on commit 01bc11d

Please sign in to comment.