@@ -69,7 +69,10 @@ function Worker(options) {
69
69
* @param {function } callback
70
70
*/
71
71
Worker . prototype . start = function ( cb ) {
72
- this . updatePool ( cb ) ;
72
+ this . updatePool ( err => {
73
+ this . logger . info ( 'Worker started' ) ;
74
+ cb ( err ) ;
75
+ } ) ;
73
76
} ;
74
77
/**
75
78
* Get a report of the actual situation of the worker
@@ -117,30 +120,39 @@ Worker.prototype.removePooler = function (cb) {
117
120
118
121
/**
119
122
* Close the worker, this function might take 60 seconds to finish to do step function design
123
+ * remove all the events attached to the worker
120
124
* @param {function } callback
121
125
*/
122
126
123
127
Worker . prototype . close = function ( cb ) {
124
- this . logger . info ( 'Closing the worker ... this might take 60 seconds' ) ;
128
+ this . stop ( cb ) ;
129
+ this . removeAllListeners ( ) ;
130
+ } ;
131
+
132
+ /**
133
+ * Stop the worker
134
+ * But does not remove all the events attached to it
135
+ * NB: worker.concurrency is set to 0
136
+ * @param {function } callback
137
+ */
138
+
139
+ Worker . prototype . stop = function ( cb ) {
140
+ this . logger . info ( 'Stopping the worker ... this might take 60 seconds' ) ;
125
141
this . concurrency = 0 ;
126
142
this . updatePool ( err => {
127
- this . logger . info ( 'Worker closed ' ) ;
143
+ this . logger . info ( 'Worker stopped ' ) ;
128
144
cb ( err ) ;
129
145
} ) ;
130
- this . removeAllListeners ( ) ;
131
146
} ;
132
147
133
148
Worker . prototype . restart = function ( cb ) {
134
- this . logger . info ( 'Restarting the worker ... this might take 60 seconds' ) ;
135
149
const oldConcurrency = this . concurrency ;
136
- this . concurrency = 0 ;
137
- this . updatePool ( ( ) => {
138
- this . logger . info ( 'Worker closed' ) ;
150
+ this . stop ( err => {
151
+ if ( err ) {
152
+ return cb ( err ) ;
153
+ }
139
154
this . concurrency = oldConcurrency ;
140
- this . updatePool ( err => {
141
- this . logger . info ( 'Worker started' ) ;
142
- cb ( err ) ;
143
- } ) ;
155
+ this . start ( cb ) ;
144
156
} ) ;
145
157
} ;
146
158
0 commit comments