X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fabstract-worker.ts;h=ebbefc75ba4cc8c4e09bcc3073e372085466c181;hb=refs%2Fheads%2Fmaster;hp=9b9ded5e9d1cc1267846fb9e0279d88de405262f;hpb=3a5027122ca6401ae1d755843b20f714c61e3240;p=poolifier.git diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 9b9ded5e..ebbefc75 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -78,7 +78,6 @@ export abstract class AbstractWorker< /** * Handler id of the `activeInterval` worker activity check. */ - // eslint-disable-next-line no-undef protected activeInterval?: NodeJS.Timeout /** @@ -355,9 +354,10 @@ export abstract class AbstractWorker< switch (taskFunctionOperation) { case 'add': response = this.addTaskFunction(taskFunctionProperties.name, { - // eslint-disable-next-line no-new-func + // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func taskFunction: new Function( - `return ${taskFunction}` + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + `return ${taskFunction!}` )() as TaskFunction, ...(taskFunctionProperties.priority != null && { priority: taskFunctionProperties.priority, @@ -377,15 +377,16 @@ export abstract class AbstractWorker< response = { status: false, error: new Error('Unknown task operation') } break } + const { status, error } = response this.sendToMainWorker({ taskFunctionOperation, - taskFunctionOperationStatus: response.status, + taskFunctionOperationStatus: status, taskFunctionProperties, - ...(!response.status && - response.error != null && { + ...(!status && + error != null && { workerError: { name: taskFunctionProperties.name, - message: this.handleError(response.error as Error | string), + message: this.handleError(error as Error | string), }, }), }) @@ -398,7 +399,7 @@ export abstract class AbstractWorker< protected handleKillMessage (message: MessageValue): void { this.stopCheckActive() if (isAsyncFunction(this.opts.killHandler)) { - ;(this.opts.killHandler() as Promise) + ;(this.opts.killHandler as () => Promise)() .then(() => { this.sendToMainWorker({ kill: 'success' }) return undefined @@ -408,7 +409,7 @@ export abstract class AbstractWorker< }) } else { try { - this.opts.killHandler?.() + ;(this.opts.killHandler as (() => void) | undefined)?.() this.sendToMainWorker({ kill: 'success' }) } catch { this.sendToMainWorker({ kill: 'failure' }) @@ -426,7 +427,7 @@ export abstract class AbstractWorker< throw new Error('Message worker id is not set') } else if (message.workerId !== this.id) { throw new Error( - `Message worker id ${message.workerId} does not match the worker id ${this.id}` + `Message worker id ${message.workerId.toString()} does not match the worker id ${this.id.toString()}` ) } } @@ -514,7 +515,8 @@ export abstract class AbstractWorker< workerError: { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion name: name!, - message: `Task function '${name}' not found`, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + message: `Task function '${name!}' not found`, data, }, taskId,