querysub 0.294.0 → 0.296.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.294.0",
3
+ "version": "0.296.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",
@@ -66,7 +66,8 @@ function onLiveHashChange(liveHash: string, refreshThresholdTime: number) {
66
66
  if (liveHash === curHash) return;
67
67
  let prevHash = curHash;
68
68
  // Don't notify the user right away. Hopefully they refresh naturally, and we never have to notify them at all!
69
- let notifyIntervals = [0.4, 0.75, 1];
69
+ // Also, refresh BEFORE the server dies, not exactly when it is about to die
70
+ let notifyIntervals = [0.4, 0.75, 0.95];
70
71
  console.log(blue(`Client liveHash changed ${liveHash}, prev hash: ${prevHash}`));
71
72
  // If we are replacing an already existing notification, don't show immediately
72
73
  let skipFirst = false;
@@ -359,9 +359,9 @@ type ServiceConfig = ${serviceConfigType}
359
359
  </div>
360
360
  {serviceInfo && (
361
361
  <>
362
- <div title={formatVeryNiceDateTime(serviceInfo.lastLaunchedTime)}>
362
+ {!!serviceInfo.lastLaunchedTime && <div title={formatVeryNiceDateTime(serviceInfo.lastLaunchedTime)}>
363
363
  Uptime: {formatTime(now - serviceInfo.lastLaunchedTime)}
364
- </div>
364
+ </div>}
365
365
  <div>
366
366
  Launches: {serviceInfo.totalTimesLaunched}
367
367
  </div>
@@ -349,6 +349,7 @@ const runScreenCommand = measureWrap(async function runScreenCommand(config: {
349
349
  // REMOVE the nodeId file, so we the node isn't terminated!
350
350
  await fs.promises.unlink(nodeIdPath);
351
351
  try {
352
+ console.log(green(`Triggering rolling update notification to ${nodeId} for ${screenName} at ${new Date().toLocaleString()}`));
352
353
  await triggerRollingUpdate({
353
354
  nodeId,
354
355
  time: rollingFinalTime,
@@ -356,6 +357,8 @@ const runScreenCommand = measureWrap(async function runScreenCommand(config: {
356
357
  } catch (e: any) {
357
358
  console.warn(`Error triggering rolling update notification to ${nodeId} for ${screenName}: ${e.stack}`);
358
359
  }
360
+ } else {
361
+ console.log(red(`No nodeId file found for ${screenName}, not triggering rolling update notification`));
359
362
  }
360
363
  let rollingScreenName = screenName + "-rolling" + SCREEN_SUFFIX;
361
364
  console.log(green(`Renaming screen ${screenName} to ${rollingScreenName} for rolling interval ${config.rollingWindow} at ${new Date().toLocaleString()}`));
@@ -487,6 +490,13 @@ let lastLaunchedTimePerService = new Map<string, number>();
487
490
 
488
491
  async function quickIsOutdated() {
489
492
  let machineId = getOwnMachineId();
493
+ // If any rolling are ready to restart, we are outdated
494
+ for (let [rollingScreenName, rollingInfo] of rollingKeepScreenAlive) {
495
+ if (rollingInfo.pinnedTime + rollingInfo.pinnedDuration < Date.now()) {
496
+ console.log(red(`Rolling screen ${rollingScreenName} is finished, doing a full resync`));
497
+ return true;
498
+ }
499
+ }
490
500
  let configs = await serviceConfigs.values();
491
501
  let relevantConfigs = configs.filter(config => config.machineIds.includes(machineId)).filter(x => x.parameters.deploy);
492
502
  let screens = await getScreenState();
@@ -508,7 +518,6 @@ async function quickIsOutdated() {
508
518
  if (!fs.existsSync(parameterPath)) return true;
509
519
  let prevParameters = await fs.promises.readFile(parameterPath, "utf8");
510
520
  if (prevParameters !== newParametersString) return true;
511
-
512
521
  }
513
522
  }
514
523
  return false;
@@ -22,6 +22,7 @@ import { isNode } from "typesafecss";
22
22
  import { DeployProgress, deployFunctions, deployGetFunctions } from "../4-deploy/deployFunctions";
23
23
  import { FunctionSpec, functionSchema } from "../3-path-functions/PathFunctionRunner";
24
24
  import { Querysub } from "../4-querysub/QuerysubController";
25
+ import { green, red } from "socket-function/src/formatting/logColors";
25
26
 
26
27
  const SERVICE_FOLDER_NAME = "machine-services";
27
28
  export const SERVICE_FOLDER = `${SERVICE_FOLDER_NAME}/`;
@@ -101,7 +102,11 @@ async function registerNodeForMachineCleanup(nodeId: string) {
101
102
  let currentPath = path.resolve(".").replaceAll("\\", "/");
102
103
  let array = currentPath.split("/");
103
104
  if (array.at(-1) === "git" && array.at(-2) === SERVICE_FOLDER_NAME) {
104
- await fs.promises.writeFile(array.slice(0, -2).join("/") + "/" + SERVICE_NODE_FILE_NAME, nodeId);
105
+ let nodeIdPath = array.slice(0, -1).join("/") + "/" + SERVICE_NODE_FILE_NAME;
106
+ console.log(green(`Registering node for machine cleanup at ${nodeIdPath}`));
107
+ await fs.promises.writeFile(nodeIdPath, nodeId);
108
+ } else {
109
+ console.log(red(`Not registering node for machine cleanup because we are not in the service folder: ${currentPath}`));
105
110
  }
106
111
  }
107
112