repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: sensible defaults for worker choice strategy policy
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
round-robin-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
index fdf5ac84fddf87235b1d7732e81f2ccff3aae53b..7a50db7b6387d5426dd4c4847482c5314f611b74 100644
(file)
--- a/
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
@@
-4,7
+4,6
@@
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- StrategyPolicy,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
@@
-22,11
+21,6
@@
export class RoundRobinWorkerChoiceStrategy<
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
- /** @inheritDoc */
- public readonly strategyPolicy: StrategyPolicy = {
- useDynamicWorker: true
- }
-
/** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
/** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
@@
-48,9
+42,14
@@
export class RoundRobinWorkerChoiceStrategy<
}
/** @inheritDoc */
}
/** @inheritDoc */
- public choose (): number {
+ public choose (): number
| undefined
{
const chosenWorkerNodeKey = this.nextWorkerNodeKey
this.roundRobinNextWorkerNodeKey()
const chosenWorkerNodeKey = this.nextWorkerNodeKey
this.roundRobinNextWorkerNodeKey()
+ if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) {
+ this.nextWorkerNodeKey = undefined
+ this.previousWorkerNodeKey =
+ chosenWorkerNodeKey ?? this.previousWorkerNodeKey
+ }
return chosenWorkerNodeKey
}
return chosenWorkerNodeKey
}
@@
-66,10
+65,11
@@
export class RoundRobinWorkerChoiceStrategy<
return true
}
return true
}
- private roundRobinNextWorkerNodeKey ():
voi
d {
+ private roundRobinNextWorkerNodeKey ():
number | undefine
d {
this.nextWorkerNodeKey =
this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
? 0
this.nextWorkerNodeKey =
this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
? 0
- : this.nextWorkerNodeKey + 1
+ : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
+ return this.nextWorkerNodeKey
}
}
}
}