querysub 0.35.0 → 0.37.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.35.0",
3
+ "version": "0.37.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",
@@ -41,6 +41,8 @@ let backblazeCreds = lazy((): BackblazeCreds => (
41
41
  const getAPI = lazy(async () => {
42
42
  let creds = backblazeCreds();
43
43
 
44
+ // NOTE: On errors, our retry code resets this lazy, so we DO get new authorize when needed.
45
+ // TODO: Maybe we should get new authorization periodically at well?
44
46
  let authorizeRaw = await httpsRequest("https://api.backblazeb2.com/b2api/v2/b2_authorize_account", undefined, "GET", undefined, {
45
47
  headers: {
46
48
  Authorization: "Basic " + Buffer.from(creds.applicationKeyId + ":" + creds.applicationKey).toString("base64"),
@@ -65,11 +67,14 @@ const getAPI = lazy(async () => {
65
67
  arg = { accountId: auth.accountId, ...arg };
66
68
  }
67
69
  try {
68
- let result = await httpsRequest(auth.apiUrl + "/b2api/v2/" + name, Buffer.from(JSON.stringify(arg)), type, undefined, {
70
+ let url = auth.apiUrl + "/b2api/v2/" + name;
71
+ console.log(`Backblaze API ${type} ${url}`);
72
+ let result = await httpsRequest(url, Buffer.from(JSON.stringify(arg)), type, undefined, {
69
73
  headers: {
70
74
  Authorization: auth.authorizationToken,
71
75
  }
72
76
  });
77
+ console.log(`Finished Backblaze API ${type} ${url}`);
73
78
  return JSON.parse(result.toString());
74
79
  } catch (e: any) {
75
80
  throw new Error(`Error in ${name}, arg ${JSON.stringify(arg).slice(0, 1000)}: ${e.stack}`);
@@ -479,8 +484,8 @@ class Backblaze {
479
484
  await this.apiRetryLogic(async (api) => {
480
485
  try {
481
486
  await api.hideFile({ bucketId: this.bucketId, fileName: fileName });
482
- } catch {
483
- // Probably already deleted
487
+ } catch (e: any) {
488
+ this.log(`backblaze error in hide, possibly already hidden ${fileName}\n${e.stack}`);
484
489
  }
485
490
  });
486
491
 
@@ -267,6 +267,7 @@ async function runHeartbeatAuditLoop() {
267
267
  await runInfinitePollCallAtStart(CHECK_INTERVAL * 0.9, async () => {
268
268
  if (shutdown) return;
269
269
  // Wait a bit longer, to try to prevent all nodes from synchronizing their audit times.
270
+ console.log(magenta(`Auditing node list`));
270
271
  await delay(CHECK_INTERVAL * Math.random() * 0.1);
271
272
  //console.log(magenta(`Auditing node list`));
272
273
 
@@ -278,7 +279,7 @@ async function runHeartbeatAuditLoop() {
278
279
  let pendingDeadCount = 0;
279
280
 
280
281
  let removedNodeIds: string[] = [];
281
- await Promise.all(nodeIds.map(async nodeId => {
282
+ for (let nodeId of nodeIds) {
282
283
  let lastTime = Number((await archives().get(nodeId))?.toString()) || 0;
283
284
  if (lastTime < deadTime) {
284
285
  // Increment the dead count
@@ -298,7 +299,7 @@ async function runHeartbeatAuditLoop() {
298
299
  deadCount.delete(nodeId);
299
300
  diskLog("Read node heartbeat", { nodeId, lastTime });
300
301
  }
301
- }));
302
+ }
302
303
  if (pendingDeadCount) {
303
304
  console.log(blue(`Pending dead nodes ${pendingDeadCount}/${nodeIds.length}`));
304
305
  }
@@ -306,7 +307,7 @@ async function runHeartbeatAuditLoop() {
306
307
  if (removedNodeIds.length > 0) {
307
308
  console.log(blue(`Removed ${removedNodeIds.length}/${nodeIds.length} nodes from node list`), { removedNodeIds });
308
309
  await syncArchives();
309
- void tellEveryoneNodesChanges();
310
+ await tellEveryoneNodesChanges();
310
311
  }
311
312
  });
312
313
  }