-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#36): create scaler emitter to handle scaling down services
Co-authored-by: nukdown <belchior.emanoel@gmail.com>
- Loading branch information
1 parent
0f05c67
commit 48bde65
Showing
2 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
const EventEmitter = require('events') | ||
|
||
class ScaleEmitter extends EventEmitter { | ||
constructor() { | ||
super() | ||
this._eventRelease = 'releaseService' | ||
this.on(this._eventRelease, this.scaleDownServices) | ||
} | ||
|
||
scaleDownServices(serviceName, servicePool) { | ||
if(servicePool.servicesList[serviceName].length > 1) { | ||
console.log('Releasing service') | ||
delete servicePool.servicesList[serviceName].pop() | ||
} | ||
} | ||
|
||
emit(serviceName, servicePool) { | ||
super.emit(this._eventType, serviceName, servicePool) | ||
} | ||
} | ||
|
||
module.exports = ScaleEmitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters