@yarkivaev/scada 2.6.17 → 2.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/scada",
3
- "version": "2.6.17",
3
+ "version": "2.6.18",
4
4
  "description": "SCADA domain objects, state persistence, and plant monitoring",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,6 +28,30 @@ function freshRead(report, input, { now, freshnessMs, controlEpoch, clockSkewMs
28
28
  && Number.isFinite(row.lastRead) && row.lastRead <= now + clockSkewMs && now - row.lastRead <= freshnessMs;
29
29
  });
30
30
  }
31
+ function holderOf(slots, task) {
32
+ const holders = slots.filter((node) => { return node.assignments.some((row) => { return row.taskId === task.taskId; }); });
33
+ return holders.length === 1 ? holders[0] : null;
34
+ }
35
+ function destination(slots, task, holder, timing) {
36
+ const input = holder.assignments.find((row) => { return row.taskId === task.taskId; });
37
+ if (timing.now - (input.assignedAt ?? 0) < timing.replacementDelayMs) { return null; }
38
+ const candidates = slots.filter((node) => {
39
+ return node.live && wanted(task, node) && (node.id === holder.id || node.load + (task.cost ?? 1) <= node.capacity);
40
+ });
41
+ const home = [...candidates].sort(byPlace(task))[0];
42
+ return home && home.id !== holder.id ? home : null;
43
+ }
44
+ function reclaim(slots, tasks, timing) {
45
+ tasks.filter((task) => { return copies(task) === 1; }).forEach((task) => {
46
+ const holder = holderOf(slots, task);
47
+ const home = holder ? destination(slots, task, holder, timing) : null;
48
+ if (!home) { return; }
49
+ holder.assignments = holder.assignments.filter((row) => { return row.taskId !== task.taskId; });
50
+ holder.load -= task.cost ?? 1;
51
+ home.assignments.push({ taskId: task.taskId, specVersion: 1, generation: 0, assignedAt: timing.now, spec: task.spec });
52
+ home.load += task.cost ?? 1;
53
+ });
54
+ }
31
55
  function retain(slots, tasks, owners, observed, timing) {
32
56
  for (const task of tasks) {
33
57
  const confirmed = owners(task).filter((node) => {
@@ -119,6 +143,7 @@ export default function schedule(catalog, reports, current, { now = Date.now(),
119
143
  }
120
144
  }
121
145
  }
146
+ reclaim(slots, tasks, { now, replacementDelayMs });
122
147
  retain(slots, tasks, owners, observed, { now, freshnessMs, controlEpoch, clockSkewMs });
123
148
  return snapshots(slots, taskMap, catalog, observed, { now, freshnessMs, clockSkewMs });
124
149
  }