querysub 0.620.0 → 0.621.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.
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ require("typenode");
4
+ require("../src/deployManager/emergencyUpdateMain");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "querysub",
3
- "version": "0.620.0",
3
+ "version": "0.621.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",
@@ -55,6 +55,7 @@
55
55
  "error-watch-public": "./bin/error-watch-public.js",
56
56
  "audit-imports": "./bin/audit-imports.js",
57
57
  "audit-disk-values": "./bin/audit-disk-values.js",
58
+ "emergency-update": "./bin/emergency-update.js",
58
59
  "mcp-indexed-logs": "./bin/mcp-indexed-logs.js",
59
60
  "autofix": "./bin/autofix.js",
60
61
  "storageserve": "./bin/storageserve.js"
@@ -78,7 +79,7 @@
78
79
  "node-forge": "https://github.com/sliftist/forge#e618181b469b07bdc70b968b0391beb8ef5fecd6",
79
80
  "pako": "^2.1.0",
80
81
  "peggy": "^5.0.6",
81
- "sliftutils": "^1.7.89",
82
+ "sliftutils": "^1.7.90",
82
83
  "socket-function": "^1.2.30",
83
84
  "terser": "^5.31.0",
84
85
  "typenode": "^6.6.1",
@@ -83,7 +83,7 @@ function archiveBuilder(bucket: string, overrides: Partial<RemoteConfigBase>) {
83
83
  ]);
84
84
 
85
85
  return createArchives({
86
- version: 22,
86
+ version: 23,
87
87
  sources,
88
88
  });
89
89
  }
@@ -0,0 +1,78 @@
1
+ import "../inject";
2
+
3
+ import { Querysub } from "../4-querysub/Querysub";
4
+ import { logErrors } from "../errors";
5
+ import { disablePathAuditer } from "../diagnostics/pathAuditerCallback";
6
+ import { formatDateTime } from "socket-function/src/formatting/format";
7
+ import { green, magenta } from "socket-function/src/formatting/logColors";
8
+ import { delay } from "socket-function/src/batching";
9
+ import { MachineServiceControllerBase, ServiceConfig } from "./machineSchema";
10
+
11
+ // setServiceConfigs notifies the machines without awaiting the notifications, so we linger before exiting to let them go out. If they are lost anyway (ex, the machines are unreachable), the machines still pick up the new configs on their fallback resync poll.
12
+ const NOTIFY_GRACE_PERIOD = 10 * 1000;
13
+
14
+ // The emergency workflow from the services list page, as one command: commit/publish/push querysub, commit/push the service repo, then point every service config at the new commit with no overlap. Everything here writes to the service configs archives directly, which falls back to backblaze, so this works while the storage servers (and therefore the deploy pages) are down.
15
+ async function main() {
16
+ disablePathAuditer();
17
+ await Querysub.hostService("emergency-update");
18
+
19
+ let controller = new MachineServiceControllerBase();
20
+ let commitMessage = `emergency update ${formatDateTime(Date.now())}`;
21
+
22
+ let gitInfo = await controller.getGitInfo();
23
+ console.log(magenta(`Starting emergency update of ${gitInfo.repoUrl}`), {
24
+ commitMessage,
25
+ querysubUncommittedFiles: gitInfo.querysubUncommitted.length,
26
+ uncommittedFiles: gitInfo.uncommitted.length,
27
+ });
28
+
29
+ if (gitInfo.querysubUncommitted.length > 0) {
30
+ console.log(magenta(`Committing, publishing, and pushing querysub (${gitInfo.querysubUncommitted.length} files changed)`));
31
+ await controller.commitPushAndPublishQuerysub(commitMessage);
32
+ } else {
33
+ console.log(`Querysub has no uncommitted changes, skipping the querysub publish`);
34
+ }
35
+
36
+ // Re-read, as publishing querysub updates our package.json, which then needs to be committed here
37
+ gitInfo = await controller.getGitInfo();
38
+ if (gitInfo.uncommitted.length > 0) {
39
+ console.log(magenta(`Committing and pushing the service repo (${gitInfo.uncommitted.length} files changed)`));
40
+ await controller.commitPushService(commitMessage);
41
+ } else {
42
+ console.log(`The service repo has no uncommitted changes, skipping the commit`);
43
+ }
44
+
45
+ // Re-read, as latestRef must include the commit we just pushed
46
+ gitInfo = await controller.getGitInfo();
47
+
48
+ let serviceIds = await controller.getServiceList();
49
+ let configs: ServiceConfig[] = [];
50
+ for (let serviceId of serviceIds) {
51
+ let config = await controller.getServiceConfig(serviceId);
52
+ if (config) configs.push(config);
53
+ }
54
+ let outdated = configs.filter(config =>
55
+ config.parameters.repoUrl === gitInfo.repoUrl
56
+ && config.parameters.gitRef !== gitInfo.latestRef
57
+ );
58
+ console.log(`Services: ${configs.length} total, ${outdated.length} on an old commit (latest is ${gitInfo.latestRef})`);
59
+ if (outdated.length === 0) {
60
+ console.log(green(`All services are already on the latest commit, nothing to deploy`));
61
+ return;
62
+ }
63
+
64
+ let now = Date.now();
65
+ for (let config of outdated) {
66
+ console.log(`Updating ${config.parameters.key}: ${config.parameters.gitRef} => ${gitInfo.latestRef} (release at ${formatDateTime(now)}, no overlap)`);
67
+ config.parameters.gitRef = gitInfo.latestRef;
68
+ config.parameters.releaseTime = now;
69
+ config.parameters.overlapTime = 0;
70
+ }
71
+ await controller.setServiceConfigs(outdated);
72
+ console.log(`Wrote ${outdated.length} service configs, waiting for machine notifications to go out`);
73
+ await delay(NOTIFY_GRACE_PERIOD);
74
+
75
+ console.log(green(`Emergency update complete: ${outdated.length} services updating to ${gitInfo.latestRef}`));
76
+ }
77
+
78
+ main().catch(logErrors).finally(() => process.exit());
@@ -1,6 +1,3 @@
1
- require("debugbreak")(2);
2
- debugger;
3
-
4
1
  import { isNode } from "typesafecss";
5
2
  import { partialCopyObject } from "../../misc";
6
3
  import { canHaveChildren } from "socket-function/src/types";