| 136 | }); |
| 137 | } |
| 138 | _getWorkerInstance(argv) { |
| 139 | const port = argv.port || think.config('port'); |
| 140 | const instance = new thinkCluster.Worker({ |
| 141 | port, |
| 142 | host: think.config('host'), |
| 143 | sticky: think.config('stickyCluster'), |
| 144 | createServer() { |
| 145 | const createServerFn = think.config('createServer'); |
| 146 | const callback = think.app.callback(); |
| 147 | if (createServerFn) { |
| 148 | assert(helper.isFunction(createServerFn), 'config.createServer must be a function'); |
| 149 | } |
| 150 | const server = createServerFn ? createServerFn(callback) : http.createServer(callback); |
| 151 | think.app.server = server; |
| 152 | return server; |
| 153 | }, |
| 154 | logger: think.logger.error.bind(think.logger), |
| 155 | processKillTimeout: think.config('processKillTimeout'), |
| 156 | onUncaughtException: think.config('onUncaughtException'), |
| 157 | onUnhandledRejection: think.config('onUnhandledRejection') |
| 158 | }); |
| 159 | return instance; |
| 160 | } |
| 161 | /** |
| 162 | * run in worker |
| 163 | * @param {Object} argv |