## [Unreleased]
+### Added
+
+- Add `destroy` event to pool API.
+
## [2.6.26] - 2023-08-15
### Added
- Add kill handler to worker options allowing to execute custom code when worker is killed.
-- Add listTaskFunctions() method to pool API.
+- Add `listTaskFunctions()` method to pool API.
- SMTP server pool example: nodemailer.
## [2.6.25] - 2023-08-13
await this.destroyWorkerNode(workerNodeKey)
})
)
+ this.emitter?.emit(PoolEvents.destroy)
}
protected async sendKillMessageToWorker (
* Enumeration of pool events.
*/
export const PoolEvents = Object.freeze({
- full: 'full',
ready: 'ready',
busy: 'busy',
+ full: 'full',
+ destroy: 'destroy',
error: 'error',
taskError: 'taskError'
} as const)
*
* Events that can currently be listened to:
*
- * - `'full'`: Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected.
* - `'ready'`: Emitted when the number of workers created in the pool has reached the minimum size expected and are ready.
* - `'busy'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing at least one task.
+ * - `'full'`: Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected.
+ * - '`destroy`': Emitted when the pool is destroyed.
* - `'error'`: Emitted when an uncaught error occurs.
* - `'taskError'`: Emitted when an error occurs while executing a task.
*/
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', min)
+ let poolDestroy = 0
+ pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(numberOfExitEvents).toBe(min)
+ expect(poolDestroy).toBe(1)
})
it('Validation of inputs test', () => {
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', numberOfWorkers)
+ let poolDestroy = 0
+ pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(numberOfExitEvents).toBe(numberOfWorkers)
+ expect(poolDestroy).toBe(1)
})
it('Verify that cluster pool options are checked', async () => {
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', min)
+ let poolDestroy = 0
+ pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(numberOfExitEvents).toBe(min)
+ expect(poolDestroy).toBe(1)
})
it('Validation of inputs test', () => {
it('Shutdown test', async () => {
const exitPromise = waitWorkerEvents(pool, 'exit', numberOfThreads)
+ let poolDestroy = 0
+ pool.emitter.on(PoolEvents.destroy, () => ++poolDestroy)
await pool.destroy()
const numberOfExitEvents = await exitPromise
expect(numberOfExitEvents).toBe(numberOfThreads)
+ expect(poolDestroy).toBe(1)
})
it('Verify that thread pool options are checked', async () => {