- public getTasksWorkerUsage (name: string): WorkerUsage | undefined {
- if (!this.tasksUsage.has(name)) {
- this.tasksUsage.set(name, this.initWorkerUsage())
+ public getTaskFunctionWorkerUsage (name: string): WorkerUsage | undefined {
+ if (!Array.isArray(this.info.taskFunctionNames)) {
+ throw new Error(
+ `Cannot get task function worker usage for task function name '${name}' when task function names list is not yet defined`
+ )
+ }
+ if (
+ Array.isArray(this.info.taskFunctionNames) &&
+ this.info.taskFunctionNames.length < 3
+ ) {
+ throw new Error(
+ `Cannot get task function worker usage for task function name '${name}' when task function names list has less than 3 elements`
+ )
+ }
+ if (name === DEFAULT_TASK_NAME) {
+ name = this.info.taskFunctionNames[1]
+ }
+ if (!this.taskFunctionsUsage.has(name)) {
+ this.taskFunctionsUsage.set(name, this.initTaskFunctionWorkerUsage(name))
+ }
+ return this.taskFunctionsUsage.get(name)
+ }
+
+ private async startOnEmptyQueue (): Promise<void> {
+ if (
+ this.onEmptyQueueCount > 0 &&
+ (this.usage.tasks.executing > 0 || this.tasksQueue.size > 0)
+ ) {
+ this.onEmptyQueueCount = 0
+ return