querysub 0.222.0 → 0.224.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.222.0",
3
+ "version": "0.224.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",
@@ -75,7 +75,7 @@ export class ServicesListPage extends qreact.Component {
75
75
  });
76
76
  let totalLaunches = config.machineIds.reduce((acc, machineId) => {
77
77
  let machineInfo = getMachineInfo(machineId);
78
- return acc + (machineInfo?.services[serviceId].totalTimesLaunched || 0);
78
+ return acc + (machineInfo?.services[serviceId]?.totalTimesLaunched || 0);
79
79
  }, 0);
80
80
  let unknown = config.machineIds.length - runningMachines.length - failingMachines.length - missingMachines.length;
81
81
  return <div key={serviceId}
@@ -96,7 +96,7 @@ export class ServicesListPage extends qreact.Component {
96
96
  <div className={css.fontSize(14).boldStyle}>{config.info.title}</div>
97
97
  <div>{config.parameters.key}</div>
98
98
  <div>
99
- {config.machineIds.length} configured {failingMachines.length > 0 && `(${failingMachines.length} failing)`} {missingMachines.length > 0 && `(${missingMachines.length} missing machines)`} {unknown > 0 && `(${unknown} unknown)`} • {totalLaunches} launches •
99
+ {config.machineIds.length} configured {failingMachines.length > 0 && `(${failingMachines.length} failing)`} {missingMachines.length > 0 && `(${missingMachines.length} machine hasn't run service yet)`} {unknown > 0 && `(${unknown} unknown)`} • {totalLaunches} launches •
100
100
  Deploy: {config.parameters.deploy ? "enabled" : "disabled"}
101
101
  </div>
102
102
  </div>
@@ -201,8 +201,9 @@ const ensureGitSynced = measureWrap(async function ensureGitSynced(config: {
201
201
 
202
202
 
203
203
  let launchesPerService = new Map<string, number>();
204
+ let lastLaunchedTimePerService = new Map<string, number>();
204
205
 
205
- const resyncServices = runInSerial(measureWrap(async function resyncServices() {
206
+ const resyncServicesBase = runInSerial(measureWrap(async function resyncServices() {
206
207
  console.log(magenta("Resyncing services"));
207
208
  let machineId = getOwnMachineId();
208
209
  let configs = await serviceConfigs.values();
@@ -219,9 +220,12 @@ const resyncServices = runInSerial(measureWrap(async function resyncServices() {
219
220
  for (let i = 0; i < matchedCount; i++) {
220
221
 
221
222
  let launchCount = launchesPerService.get(config.serviceId) || 0;
222
- // Always increase, as this is the only way to detect if a service is repeatedly crashing. If this is really high for one service, but not others... it's crashing a lot.
223
- launchCount++;
224
- launchesPerService.set(config.serviceId, launchCount);
223
+ let lastLaunchedTime = lastLaunchedTimePerService.get(config.serviceId) || 0;
224
+ machineInfo.services[config.serviceId] = {
225
+ lastLaunchedTime,
226
+ errorFromLastRun: "",
227
+ totalTimesLaunched: launchCount,
228
+ };
225
229
  try {
226
230
  let folder = root + config.parameters.key + "-" + i + "/";
227
231
  let screenName = getScreenName({
@@ -276,19 +280,19 @@ const resyncServices = runInSerial(measureWrap(async function resyncServices() {
276
280
  }
277
281
  console.log(green(`Service ${magenta(screenName)} is verified to be running after starting.`));
278
282
 
279
- machineInfo.services[config.serviceId] = {
280
- lastLaunchedTime: Date.now(),
281
- errorFromLastRun: "",
282
- totalTimesLaunched: launchCount,
283
- };
283
+ launchCount++;
284
+ lastLaunchedTime = Date.now();
284
285
  } catch (e: any) {
286
+ // Increase on failures too, as this is the only way to detect if a service is repeatedly crashing. If this is really high for one service, but not others... it's crashing a lot.
287
+ launchCount++;
288
+ lastLaunchedTime = Date.now();
285
289
  console.error(`Error resyncing service ${magenta(config.serviceId)} (${config.parameters?.key}): ${e.stack}`);
286
- machineInfo.services[config.serviceId] = {
287
- lastLaunchedTime: Date.now(),
288
- errorFromLastRun: e.stack,
289
- totalTimesLaunched: launchCount,
290
- };
290
+ machineInfo.services[config.serviceId].errorFromLastRun = e.stack;
291
291
  }
292
+ machineInfo.services[config.serviceId].totalTimesLaunched = launchCount;
293
+ machineInfo.services[config.serviceId].lastLaunchedTime = lastLaunchedTime;
294
+ lastLaunchedTimePerService.set(config.serviceId, lastLaunchedTime);
295
+ launchesPerService.set(config.serviceId, launchCount);
292
296
  }
293
297
  }
294
298
 
@@ -300,10 +304,18 @@ const resyncServices = runInSerial(measureWrap(async function resyncServices() {
300
304
  }
301
305
 
302
306
  await machineInfos.set(machineId, machineInfo);
307
+ console.log(`${magenta(`Resynced ${relevantConfigs.length} services`)}:\n${JSON.stringify(machineInfo, null, 2)}`);
303
308
 
304
309
  // Don't resync TOO often, so always wait a bit
305
310
  await delay(5000);
306
311
  }));
312
+ async function resyncServices() {
313
+ try {
314
+ await resyncServicesBase();
315
+ } catch (e: any) {
316
+ console.error(`Error resyncing services: ${e.stack}`);
317
+ }
318
+ }
307
319
 
308
320
 
309
321
  async function isPIDRunning(pid: string) {
@@ -1,26 +1,3 @@
1
- 4.1) Requisition script
2
- - yarn setup-machine 153.34.64.2
3
-
4
- - I guess a nodejs script, with runPromise it should be easy...
5
- - Given remote IP, SSHes in, copies backblaze config from current machine, clones repo, setups crontab for always up wrapper, and then runs it
6
- - OH, also installs nodejs, yarn, etc
7
- - Maybe ansible, although... probably not. Especially because we can just get the AI to write this script anyway. We'll probably just have it copy over a bash script and then run that.
8
- git
9
- nodejs
10
- yarn
11
- add git permissions
12
- - Ugh... we need to use github API for this
13
- clones
14
- copies backblaze.json
15
- copy startup.sh
16
- setup crontab to startup.sh
17
- run startup.sh
18
- - We might need to have it use to github API to give the remote machine access to the repo?
19
-
20
- 4) Test on a new server, that we run temporarily with some test scripts
21
-
22
- 5) OH! Also setup swap usage on the machine, as it isn't by default often?
23
-
24
1
  6) Test again on a new server... I think something might be blocking on user input? Hmm...
25
2
 
26
3