Skip to content

Commit

Permalink
remove only those listeners that was added by division itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Sobczak committed Dec 10, 2014
1 parent fc48c8b commit 4a4e73c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 34 deletions.
73 changes: 46 additions & 27 deletions CHANGELOG.md
Expand Up @@ -2,88 +2,107 @@ CHANGELOG
=========
This project is using [Semantic Versioning 2.0.0](http://semver.org/)

1.0.0
-----

After successfully running **division** on production over one year - version 1.0.0. has been finally released.

#### Fixes
* Improve handling with broken workers. Now `master` will stop his work when a many `workers` has been killed in 5 minutes since last incident.
**NOTE:** This change could be incompatible for some applications, but most of them probably will not even notice.
* Remove all listeners from process instance, that was added by `master` process.

#### Other
* Make number of allowed `workers` suicides to be configurable (defaults to 30).
* Add more unit tests.
* Implement code coverage.
* Implement code linter.
* Move documentation to separate file (API.md).

0.4.5
-----

#### Fixes
* Fix error with writing error messages when `debug` extension was not enabled
* Fix error with writing error messages when `debug` extension was not enabled.

#### Other
* Some code cleanup
* Finished version of documentation
* Some code cleanup.
* Finished version of documentation.

0.4.4
-----

#### Fixes
* Fix error 'IPC channel is already disconnected' in test suite
* Fix error 'IPC channel is already disconnected' in test suite.

#### Other
* Update part of documentation
* Update part of documentation.

0.4.3
-----

#### Fixes
* Fix test suite for Travis CI
* Fix test suite for Travis CI.

#### Other
* Increase threshold for fast exiting workers
* Changed `npm test` reporter to more readable
* Increase threshold for fast exiting workers.
* Changed `npm test` reporter to more readable.

0.4.2
-----

#### Fixes
* Fix inconsistency of workers count when calling `increase` and `decrease` in short time period
* Fix bug with resolving paths in `watch` extension
* Fix inconsistency of workers count when calling `increase` and `decrease` in short time period.
* Fix bug with resolving paths in `watch` extension.

#### Other
* Decrease delay of spawning new workers when previous one exited
* Add new test cases for `watch` extension
* Decrease delay of spawning new workers when previous one exited.
* Add new test cases for `watch` extension.

0.4.1
-----

#### Fixes
* Fixed next case when program crashed with many **division** instances runs at once
* Fixed next case when program crashed with many **division** instances runs at once.

0.4.0
-----

#### Features
* New extension - `watch`
* New extension - `watch`.

#### Fixes
* Fixed bug with `debug` extension, which crash application when could not read properties of dead worker
* Fixed bug with `use` method, which crash system when cannot find extension to be required
* Fixed bug with `close` in Worker, which not always killing disconnected process
* Fixed bug when many **division** instances runs in one process
* Fixed bug with `debug` extension, which crash application when could not read properties of dead worker.
* Fixed bug with `use` method, which crash system when cannot find extension to be required.
* Fixed bug with `close` in Worker, which not always killing disconnected process.
* Fixed bug when many **division** instances runs in one process.

#### Other
* Added this file (CHANGELOG.md)
* Added basic test suite and Travis CI support
* Removed dependency of grunt in favour of CoffeeScript (Cakefile)
* Added this file (CHANGELOG.md).
* Added basic test suite and Travis CI support.
* Removed dependency of grunt in favor of CoffeeScript (Cakefile).

0.3.0
-----

#### Features
* New extension - `debug`
* New extension - `debug`.

#### Fixes
* Fixed `decrease` method, which don't working overall
* Fixed `decrease` method, which don't working overall.

#### Other
* Listed public attributes and methods in README.md
* Listed public attributes and methods in README.md.

0.2.0
-----

#### Features
* Added ability to use extensions
* New extension - `signals`
* Added ability to use extensions.
* New extension - `signals`.

0.1.0
-----
Initial version

Initial version.

4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -3,8 +3,8 @@ division

[![](https://img.shields.io/travis/codename-/division.svg?style=flat)](https://travis-ci.org/codename-/division) [![](https://img.shields.io/coveralls/codename-/division.svg?style=flat)](https://coveralls.io/r/codename-/division) ![](https://img.shields.io/node/v/division.svg?style=flat) [ ![](https://img.shields.io/npm/v/division.svg?style=flat)](https://npmjs.org/package/division) ![](https://img.shields.io/npm/l/division.svg?style=flat) ![](https://img.shields.io/npm/dm/division.svg?style=flat)

Simple and powerful wrapper over [node.js](http://nodejs.org/) [cluster](http://nodejs.org/api/cluster.html) API.<br>
This module is inspired by impressive but abandoned project [Cluster](https://github.com/LearnBoost/cluster) created by [@visionmedia](https://github.com/visionmedia).
Simple yet powerful wrapper over [node.js](http://nodejs.org/) [cluster](http://nodejs.org/api/cluster.html) API.<br>
This module is inspired by impressive, but abandoned project [Cluster](https://github.com/LearnBoost/cluster) created by [TJ Holowaychuk](https://github.com/tj).

## Installation

Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,14 +1,14 @@
{
"name": "division",
"version": "0.4.5",
"description": "Simple and powerful wrapper over node.js cluster API. This module is inspired by impressive but abandoned project Cluster created by visionmedia (TJ Holowaychuk)",
"version": "1.0.0",
"description": "Simple yet powerful wrapper over node.js cluster API. This module is inspired by impressive, but abandoned project Cluster created by TJ Holowaychuk.",
"author": "codename-",
"main": "lib/division.js",
"devDependencies": {
"coffee-script": "^1.8.0",
"coffeelint": "^1.6.1",
"coveralls": "^2.11.2",
"istanbul": "^0.3.2",
"istanbul": "^0.3.5",
"mocha": "^2.0.1",
"should": "^4.3.0"
},
Expand Down
20 changes: 18 additions & 2 deletions src/master.coffee
Expand Up @@ -34,6 +34,8 @@ module.exports = class Master extends EventEmitter
__define '__killed', writable: yes, value: 0
__define '__incident', writable: yes, value: 0

__define '__listeners', writable: yes, value: []

############################
#
# Define public methods
Expand All @@ -44,7 +46,15 @@ module.exports = class Master extends EventEmitter

# Register signal
__define 'addSignalListener', enumerable: yes, value: (event_or_signal, callback) ->
process.on event_or_signal, callback.bind this
# Bind scope of callback
callback = callback.bind this

# Save information about added signal listeners
@__listeners.push [event_or_signal, callback]

# Add signal listener to the process
process.on event_or_signal, callback

return this

## Runtime
Expand Down Expand Up @@ -224,11 +234,17 @@ module.exports = class Master extends EventEmitter
__define 'deregisterEvents', value: ->
if @registered

# Remove all listeners from cluster instance
do @removeAllListeners
do cluster.removeAllListeners
do process.removeAllListeners

# Remove all listeners from process instance
for [ event, listener ] in @__listeners
process.removeListener event, listener

# Reset state to the defaults
@registered = no
@__listeners.length = 0

return this

Expand Down

0 comments on commit 4a4e73c

Please sign in to comment.