1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| /**
| * 权重轮询
| */
| module.exports = function (tasks, weightIndex, weightTotal, context) {
|
| if (!tasks.length) return null;
|
| let weight = 0;
| let task;
|
| for (let i = 0; i < tasks.length; i++) {
| weight += tasks[i].weight || 0;
| if (weight > weightIndex) {
| task = tasks[i];
| break;
| }
| }
|
| context.weightIndex += 1;
| context.weightIndex %= (weightTotal + 1);
|
| return task;
| };
|
|