querysub 0.291.0 → 0.292.0

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": "querysub",
3
- "version": "0.291.0",
3
+ "version": "0.292.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -6,11 +6,11 @@ import { getAllNodeIds, getOwnNodeId } from "../-f-node-discovery/NodeDiscovery"
6
6
  import { getArchivesBackblazePublic } from "../-a-archives/archivesBackBlaze";
7
7
  import { nestArchives } from "../-a-archives/archives";
8
8
  import { SocketFunction } from "socket-function/SocketFunction";
9
- import { runInSerial, runInfinitePoll, runInfinitePollCallAtStart } from "socket-function/src/batching";
9
+ import { delay, runInSerial, runInfinitePoll, runInfinitePollCallAtStart } from "socket-function/src/batching";
10
10
  import { compare, compareArray, isNodeTrue, sort, timeInMinute } from "socket-function/src/misc";
11
11
  import { cacheLimited, lazy } from "socket-function/src/caching";
12
12
  import { canHaveChildren } from "socket-function/src/types";
13
- import { shutdown } from "../diagnostics/periodic";
13
+ import { registerShutdownHandler, shutdown } from "../diagnostics/periodic";
14
14
  import { hostArchives } from "../-b-authorities/cdnAuthority";
15
15
  import { getModuleFromConfig } from "../3-path-functions/pathFunctionLoader";
16
16
  import path from "path";
@@ -26,6 +26,7 @@ import { onEdgeNodesChanged } from "./edgeBootstrap";
26
26
  import { startEdgeNotifier } from "./edgeClientWatcher";
27
27
  import { getGitRefLive, getGitURLLive } from "./git";
28
28
  import { DeployProgress } from "./deployFunctions";
29
+ import { watchOnRollingUpdate } from "../deployManager/machineController";
29
30
 
30
31
  const UPDATE_POLL_INTERVAL = timeInMinute * 15;
31
32
  const DEAD_NODE_COUNT_THRESHOLD = 15;
@@ -41,13 +42,17 @@ const getEdgeNodeConfig = cacheLimited(10000, async (fileName: string): Promise<
41
42
  return obj;
42
43
  });
43
44
  let nextNodeNum = 1;
45
+ let registeredNodePaths = new Set<string>();
44
46
  function getNextNodePath() {
45
- return "node" + (nextNodeNum++) + "_" + getOwnNodeId();
47
+ let path = "node" + (nextNodeNum++) + "_" + getOwnNodeId();
48
+ registeredNodePaths.add(path);
49
+ return path;
46
50
  }
47
51
  function getNodeIdFromPath(path: string) {
48
52
  return path.split("_").slice(1).join("_");
49
53
  }
50
54
 
55
+ let edgeShutdown = false;
51
56
 
52
57
  export type EdgeNodesIndex = {
53
58
  edgeNodes: EdgeNodeConfig[];
@@ -85,6 +90,29 @@ export async function registerEdgeNode(config: {
85
90
  registeredEdgeNode = true;
86
91
  let host = config.host;
87
92
 
93
+
94
+ registerShutdownHandler(async () => {
95
+ edgeShutdown = true;
96
+ console.log(magenta(`Removing node from edge node list due to shutdown`));
97
+ await Promise.all(Array.from(registeredNodePaths).map(async nodePath => {
98
+ await edgeNodeStorage.del(nodePath);
99
+ }));
100
+ await updateEdgeNodesFile();
101
+ });
102
+ watchOnRollingUpdate({
103
+ callback: async (time) => {
104
+ let duration = time - Date.now();
105
+ // Wait a bit to remove ourself from the edge node list
106
+ void delay(duration * 0.2).finally(async () => {
107
+ console.log(magenta(`Removing node from edge node list due to rolling update at ${new Date().toLocaleString()}`));
108
+ await Promise.all(Array.from(registeredNodePaths).map(async nodePath => {
109
+ await edgeNodeStorage.del(nodePath);
110
+ }));
111
+ await updateEdgeNodesFile();
112
+ });
113
+ },
114
+ });
115
+
88
116
  await waitForFirstTimeSync();
89
117
 
90
118
  if (!isLocal() && !noSyncing()) {
@@ -193,6 +221,7 @@ const startUpdateLoop = lazy(async () => {
193
221
  });
194
222
 
195
223
  async function updateLoop() {
224
+ if (edgeShutdown) return;
196
225
  await runEdgeNodesAliveCheck();
197
226
  await updateEdgeNodesFile();
198
227
  }
@@ -4,7 +4,7 @@ Hmm... our cyoa servers are dying very fast... why?
4
4
  - Add rollingWindow to the definition
5
5
  - Set for public facing services (but not for scripts)
6
6
  - PathValueServer - 10 minutes
7
- - FunctionRunner - 10 minutes
7
+ - FunctionRunner - CANNOT use rolling
8
8
  - HTTP - 4 hours
9
9
  - Boostrapper - NO rolling
10
10
  - gc/join - NO rolling