(callback)
| 165 | * @param {function} callback - A callback(err, success) function. If 'success' is false then this PythonCaller should be discarded and a new one created by the parent. |
| 166 | */ |
| 167 | restart(callback) { |
| 168 | debug(`enter restart(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 169 | this._checkState([CREATED, WAITING, EXITING, EXITED]); |
| 170 | |
| 171 | if (!config.useWorkers) { |
| 172 | debug(`exit restart(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 173 | return callback(new Error('cannot restart when useWorkers=false')); |
| 174 | } |
| 175 | if (this.state == CREATED) { |
| 176 | // no need to restart if we don't have a worker |
| 177 | debug(`exit restart(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 178 | callback(null, true); |
| 179 | } else if (this.state == WAITING) { |
| 180 | this.call(null, 'restart', [], {}, (err, ret_val, _consoleLog) => { |
| 181 | if (ERR(err, callback)) return; |
| 182 | if (ret_val != 'success') return callback(new Error(`Error while restarting: ${ret_val}`)); |
| 183 | debug(`exit restart(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 184 | callback(null, true); |
| 185 | }); |
| 186 | } else if (this.state == EXITING || this.state == EXITED) { |
| 187 | debug(`exit restart(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 188 | callback(null, false); |
| 189 | } else { |
| 190 | debug(`exit restart(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 191 | callback(new Error(`invalid state ${this.state}`)); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | done() { |
| 196 | debug(`enter done(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
no test coverage detected