repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into feature/task-functions
[poolifier.git]
/
src
/
worker
/
abstract-worker.ts
diff --git
a/src/worker/abstract-worker.ts
b/src/worker/abstract-worker.ts
index 8cd370de2e3b7671c2f697c106acff3dc12e267f..11a2263a5b5238ac4f728daa8ed97f6ca013c86f 100644
(file)
--- a/
src/worker/abstract-worker.ts
+++ b/
src/worker/abstract-worker.ts
@@
-18,15
+18,11
@@
import { KillBehaviors, type WorkerOptions } from './worker-options'
import type {
TaskAsyncFunction,
TaskFunction,
import type {
TaskAsyncFunction,
TaskFunction,
+ TaskFunctionOperationReturnType,
TaskFunctions,
TaskSyncFunction
} from './task-functions'
TaskFunctions,
TaskSyncFunction
} from './task-functions'
-interface TaskFunctionOperationReturnType {
- status: boolean
- error?: Error
-}
-
const DEFAULT_MAX_INACTIVE_TIME = 60000
const DEFAULT_WORKER_OPTIONS: WorkerOptions = {
/**
const DEFAULT_MAX_INACTIVE_TIME = 60000
const DEFAULT_WORKER_OPTIONS: WorkerOptions = {
/**
@@
-217,7
+213,7
@@
export abstract class AbstractWorker<
this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
}
this.taskFunctions.set(name, boundFn)
this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
}
this.taskFunctions.set(name, boundFn)
- this.sendTaskFunction
sList
ToMainWorker()
+ this.sendTaskFunction
Names
ToMainWorker()
return { status: true }
} catch (error) {
return { status: false, error: error as Error }
return { status: true }
} catch (error) {
return { status: false, error: error as Error }
@@
-247,7
+243,7
@@
export abstract class AbstractWorker<
)
}
const deleteStatus = this.taskFunctions.delete(name)
)
}
const deleteStatus = this.taskFunctions.delete(name)
- this.sendTaskFunction
sList
ToMainWorker()
+ this.sendTaskFunction
Names
ToMainWorker()
return { status: deleteStatus }
} catch (error) {
return { status: false, error: error as Error }
return { status: deleteStatus }
} catch (error) {
return { status: false, error: error as Error }
@@
-375,8
+371,7
@@
export abstract class AbstractWorker<
workerError: {
name: taskFunctionName as string,
message: this.handleError(response.error as Error | string)
workerError: {
name: taskFunctionName as string,
message: this.handleError(response.error as Error | string)
- },
- workerId: this.id
+ }
})
}
})
}
@@
-390,11
+385,11
@@
export abstract class AbstractWorker<
if (isAsyncFunction(this.opts.killHandler)) {
(this.opts.killHandler?.() as Promise<void>)
.then(() => {
if (isAsyncFunction(this.opts.killHandler)) {
(this.opts.killHandler?.() as Promise<void>)
.then(() => {
- this.sendToMainWorker({ kill: 'success'
, workerId: this.id
})
+ this.sendToMainWorker({ kill: 'success' })
return null
})
.catch(() => {
return null
})
.catch(() => {
- this.sendToMainWorker({ kill: 'failure'
, workerId: this.id
})
+ this.sendToMainWorker({ kill: 'failure' })
})
.finally(() => {
this.emitDestroy()
})
.finally(() => {
this.emitDestroy()
@@
-404,9
+399,9
@@
export abstract class AbstractWorker<
try {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
this.opts.killHandler?.() as void
try {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
this.opts.killHandler?.() as void
- this.sendToMainWorker({ kill: 'success'
, workerId: this.id
})
+ this.sendToMainWorker({ kill: 'success' })
} catch {
} catch {
- this.sendToMainWorker({ kill: 'failure'
, workerId: this.id
})
+ this.sendToMainWorker({ kill: 'failure' })
} finally {
this.emitDestroy()
}
} finally {
this.emitDestroy()
}
@@
-458,7
+453,7
@@
export abstract class AbstractWorker<
performance.now() - this.lastTaskTimestamp >
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME)
) {
performance.now() - this.lastTaskTimestamp >
(this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME)
) {
- this.sendToMainWorker({ kill: this.opts.killBehavior
, workerId: this.id
})
+ this.sendToMainWorker({ kill: this.opts.killBehavior })
}
}
}
}
@@
-485,12
+480,11
@@
export abstract class AbstractWorker<
): void
/**
): void
/**
- * Sends t
he list of t
ask function names to the main worker.
+ * Sends task function names to the main worker.
*/
*/
- protected sendTaskFunction
sList
ToMainWorker (): void {
+ protected sendTaskFunction
Names
ToMainWorker (): void {
this.sendToMainWorker({
this.sendToMainWorker({
- taskFunctionNames: this.listTaskFunctionNames(),
- workerId: this.id
+ taskFunctionNames: this.listTaskFunctionNames()
})
}
})
}
@@
-520,7
+514,6
@@
export abstract class AbstractWorker<
message: `Task function '${name as string}' not found`,
data
},
message: `Task function '${name as string}' not found`,
data
},
- workerId: this.id,
taskId
})
return
taskId
})
return
@@
-550,7
+543,6
@@
export abstract class AbstractWorker<
this.sendToMainWorker({
data: res,
taskPerformance,
this.sendToMainWorker({
data: res,
taskPerformance,
- workerId: this.id,
taskId
})
} catch (error) {
taskId
})
} catch (error) {
@@
-560,7
+552,6
@@
export abstract class AbstractWorker<
message: this.handleError(error as Error | string),
data
},
message: this.handleError(error as Error | string),
data
},
- workerId: this.id,
taskId
})
} finally {
taskId
})
} finally {
@@
-586,7
+577,6
@@
export abstract class AbstractWorker<
this.sendToMainWorker({
data: res,
taskPerformance,
this.sendToMainWorker({
data: res,
taskPerformance,
- workerId: this.id,
taskId
})
return null
taskId
})
return null
@@
-598,7
+588,6
@@
export abstract class AbstractWorker<
message: this.handleError(error as Error | string),
data
},
message: this.handleError(error as Error | string),
data
},
- workerId: this.id,
taskId
})
})
taskId
})
})