- /**
- * Increases the number of tasks that the given worker has applied.
- *
- * @param worker - Worker which running tasks is increased.
- */
- private increaseWorkerRunningTasks (worker: Worker): void {
- this.stepWorkerRunningTasks(worker, 1)
- }
-
- /**
- * Decreases the number of tasks that the given worker has applied.
- *
- * @param worker - Worker which running tasks is decreased.
- */
- private decreaseWorkerRunningTasks (worker: Worker): void {
- this.stepWorkerRunningTasks(worker, -1)
- }
-
- /**
- * Gets tasks usage of the given worker.
- *
- * @param worker - Worker which tasks usage is returned.
- */
- private getWorkerTasksUsage (worker: Worker): TasksUsage | undefined {
- if (this.checkWorker(worker)) {
- const workerKey = this.getWorkerKey(worker) as number
- const workerEntry = this.workers.get(workerKey) as WorkerType<Worker>
- return workerEntry.tasksUsage
- }
- }
-
- /**
- * Steps the number of tasks that the given worker has applied.
- *
- * @param worker - Worker which running tasks are stepped.
- * @param step - Number of running tasks step.
- */
- private stepWorkerRunningTasks (worker: Worker, step: number): void {
- // prettier-ignore
- (this.getWorkerTasksUsage(worker) as TasksUsage).running += step
- }
-
- /**
- * Steps the number of tasks that the given worker has run.
- *
- * @param worker - Worker which has run tasks.
- * @param step - Number of run tasks step.
- */
- private stepWorkerRunTasks (worker: Worker, step: number): void {
- // prettier-ignore
- (this.getWorkerTasksUsage(worker) as TasksUsage).run += step
- }
-
- /**
- * Updates tasks runtime for the given worker.
- *
- * @param worker - Worker which run the task.
- * @param taskRunTime - Worker task runtime.
- */
- private updateWorkerTasksRunTime (
- worker: Worker,
- taskRunTime: number | undefined
- ): void {
- if (
- this.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .requiredStatistics.runTime
- ) {
- const workerTasksUsage = this.getWorkerTasksUsage(worker) as TasksUsage
- workerTasksUsage.runTime += taskRunTime ?? 0
- if (workerTasksUsage.run !== 0) {
- workerTasksUsage.avgRunTime =
- workerTasksUsage.runTime / workerTasksUsage.run
- }