## [Unreleased]
+### Added
+
+- Add `taskError` pool event for task execution error.
+- Emit pool information on `busy` and `full` pool events.
+
## [2.5.1] - 2023-06-01
### Added
- Add pool option `restartWorkerOnError` to restart worker on uncaught error. Default to `true`.
+- Add `error` pool event for uncaught worker error.
## [2.5.0] - 2023-05-31
if (promiseResponse != null) {
if (message.error != null) {
promiseResponse.reject(message.error)
+ if (this.emitter != null) {
+ this.emitter.emit(PoolEvents.taskError, {
+ error: message.error,
+ errorData: message.errorData
+ })
+ }
} else {
promiseResponse.resolve(message.data as Response)
}
private checkAndEmitEvents (): void {
if (this.emitter != null) {
+ const poolInfo = {
+ size: this.size,
+ workerNodes: this.workerNodes.length,
+ runningTasks: this.numberOfRunningTasks,
+ queuedTasks: this.numberOfQueuedTasks
+ }
if (this.busy) {
- this.emitter?.emit(PoolEvents.busy)
+ this.emitter?.emit(PoolEvents.busy, poolInfo)
}
if (this.type === PoolType.DYNAMIC && this.full) {
- this.emitter?.emit(PoolEvents.full)
+ this.emitter?.emit(PoolEvents.full, poolInfo)
}
}
}
export const PoolEvents = Object.freeze({
full: 'full',
busy: 'busy',
- error: 'error'
+ error: 'error',
+ taskError: 'taskError'
} as const)
/**
*
* - `'full'`: Emitted when the pool is dynamic and full.
* - `'busy'`: Emitted when the pool is busy.
- * - `'error'`: Emitted when an error occurs.
+ * - `'error'`: Emitted when an uncaught error occurs.
+ * - `'taskError'`: Emitted when an error occurs while executing a task.
*/
readonly emitter?: PoolEmitter
/**
*/
readonly kill?: KillBehavior | 1
/**
- * Error.
+ * Task error.
*/
readonly error?: string
+ /**
+ * Task data triggering task error.
+ */
+ readonly errorData?: unknown
/**
* Runtime.
*/
const runTime = performance.now() - startTimestamp
this.sendToMainWorker({
data: res,
- id: message.id,
runTime,
- waitTime
+ waitTime,
+ id: message.id
})
} catch (e) {
const err = this.handleError(e as Error)
- this.sendToMainWorker({ error: err, id: message.id })
+ this.sendToMainWorker({
+ error: err,
+ errorData: message.data,
+ id: message.id
+ })
} finally {
!this.isMain && (this.lastTaskTimestamp = performance.now())
}
const runTime = performance.now() - startTimestamp
this.sendToMainWorker({
data: res,
- id: message.id,
runTime,
- waitTime
+ waitTime,
+ id: message.id
})
return null
})
.catch(e => {
const err = this.handleError(e as Error)
- this.sendToMainWorker({ error: err, id: message.id })
+ this.sendToMainWorker({
+ error: err,
+ errorData: message.data,
+ id: message.id
+ })
})
.finally(() => {
!this.isMain && (this.lastTaskTimestamp = performance.now())