querysub 0.685.0 → 0.688.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.685.0",
3
+ "version": "0.688.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",
@@ -483,21 +483,21 @@ let cachedConfigs: ServiceConfig[] | undefined;
483
483
  let cachedConfigsTime = 0;
484
484
  // Set when something tells us the configs actually changed, which no interval can predict
485
485
  let configRefreshRequested = false;
486
- async function getResyncConfigs(): Promise<{ configs: ServiceConfig[]; refreshed: boolean }> {
486
+ async function getResyncConfigs(machineId: string): Promise<{ configs: ServiceConfig[]; refreshed: boolean }> {
487
487
  let force = configRefreshRequested;
488
488
  if (!force && cachedConfigs && Date.now() - cachedConfigsTime < CONFIG_REFRESH_INTERVAL) {
489
489
  return { configs: cachedConfigs, refreshed: false };
490
490
  }
491
491
  // Cleared before the read, so a change arriving DURING it is not swallowed by our own success
492
492
  configRefreshRequested = false;
493
- cachedConfigs = await getEffectiveServiceConfigs();
493
+ cachedConfigs = await getEffectiveServiceConfigs(machineId);
494
494
  cachedConfigsTime = Date.now();
495
495
  return { configs: cachedConfigs, refreshed: true };
496
496
  }
497
497
 
498
498
  const resyncServicesBase = runInSerial(measureWrap(async function resyncServices() {
499
499
  let machineId = getOwnMachineId(getDomain());
500
- let { configs: allConfigs, refreshed } = await getResyncConfigs();
500
+ let { configs: allConfigs, refreshed } = await getResyncConfigs(machineId);
501
501
  if (refreshed) {
502
502
  console.log(magenta("Resyncing services, with freshly read configs"));
503
503
  }
@@ -329,6 +329,7 @@ export class MachineServiceControllerBase {
329
329
  }
330
330
  public async setMachineConfig(machineId: string, config: MachineConfig) {
331
331
  await machineConfigs.set(machineId, config);
332
+ void this.notifyMachines([machineId], []);
332
333
  }
333
334
 
334
335
  private async notifyMachines(newMachineIds: string[], oldMachineIds: string[]) {
@@ -589,22 +590,19 @@ export class MachineServiceControllerBase {
589
590
  }
590
591
  }
591
592
 
592
- export async function getEffectiveServiceConfigs(): Promise<ServiceConfig[]> {
593
+ /** The service configs as `machineId` should see them. The machine's own config is a modifier on top: a disabled machine sees every service as not deployed, so it takes them down through the ordinary undeploy path instead of needing a second way to stop things. */
594
+ export async function getEffectiveServiceConfigs(machineId: string): Promise<ServiceConfig[]> {
593
595
  let configs = await serviceConfigs.values();
594
- let allMachineConfigs = await machineConfigs.values();
595
-
596
- let disabledMachineIds = new Set<string>();
597
- for (let machineConfig of allMachineConfigs) {
598
- if (machineConfig.disabled) {
599
- disabledMachineIds.add(machineConfig.machineId);
600
- }
601
- }
596
+ let machineConfig = await machineConfigs.get(machineId);
597
+ let disabled = machineConfig?.disabled;
602
598
 
603
599
  return configs.map(config => {
604
600
  normalizeServiceConfig(config);
605
- setMachineTargets(config.parameters, getMachineTargets(config.parameters).filter(target => !disabledMachineIds.has(target.machineId)));
606
- if (config.oldParameters) {
607
- setMachineTargets(config.oldParameters, getMachineTargets(config.oldParameters).filter(target => !disabledMachineIds.has(target.machineId)));
601
+ if (disabled) {
602
+ config.parameters.deploy = false;
603
+ if (config.oldParameters) {
604
+ config.oldParameters.deploy = false;
605
+ }
608
606
  }
609
607
  return config;
610
608
  });