@shipers-dev/multi 0.23.1 → 0.23.3

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15000,7 +15000,7 @@ import { parseArgs as parseArgs2 } from "util";
15000
15000
  // package.json
15001
15001
  var package_default = {
15002
15002
  name: "@shipers-dev/multi",
15003
- version: "0.23.1",
15003
+ version: "0.23.3",
15004
15004
  type: "module",
15005
15005
  bin: {
15006
15006
  "multi-agent": "./dist/index.js"
@@ -32695,13 +32695,13 @@ async function cmdConnect(apiUrl, config2) {
32695
32695
  heartbeat().catch(() => {});
32696
32696
  }, 200);
32697
32697
  };
32698
+ let alive = true;
32698
32699
  {
32699
32700
  const pending3 = await heartbeat();
32700
32701
  if (pending3 > 0)
32701
- drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2());
32702
+ drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2(), () => alive);
32702
32703
  }
32703
- drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2());
32704
- let alive = true;
32704
+ drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2(), () => alive);
32705
32705
  const shutdown = async (reason) => {
32706
32706
  if (!alive)
32707
32707
  return;
@@ -32749,7 +32749,7 @@ async function cmdConnect(apiUrl, config2) {
32749
32749
  try {
32750
32750
  const pending3 = await heartbeat();
32751
32751
  if (pending3 > 0)
32752
- drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2());
32752
+ drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2(), () => alive);
32753
32753
  } catch (e) {
32754
32754
  log3(`heartbeat error after tunnel restart: ${String(e)}`);
32755
32755
  }
@@ -32780,9 +32780,9 @@ async function cmdConnect(apiUrl, config2) {
32780
32780
  })();
32781
32781
  let probeFailures = 0;
32782
32782
  let tick = 0;
32783
- const PROBE_EVERY = 6;
32783
+ const PROBE_EVERY = 2;
32784
32784
  while (alive) {
32785
- await sleep5(20000);
32785
+ await sleep5(60000);
32786
32786
  if (existsSync7(STOP_PATH2)) {
32787
32787
  await shutdown("stop flag");
32788
32788
  break;
@@ -32806,7 +32806,7 @@ async function cmdConnect(apiUrl, config2) {
32806
32806
  try {
32807
32807
  const pending3 = await heartbeat();
32808
32808
  if (pending3 > 0)
32809
- drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2());
32809
+ drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2(), () => alive);
32810
32810
  } catch (e) {
32811
32811
  log3(`heartbeat error: ${String(e)}`);
32812
32812
  }
@@ -33848,7 +33848,9 @@ async function ackDispatch(apiUrl, dispatchId, secret) {
33848
33848
  log3(`ack dispatch ${dispatchId} failed: ${String(e)}`);
33849
33849
  }
33850
33850
  }
33851
- async function drainOfflineDispatches(apiUrl, deviceId, secret, db, onEnqueued) {
33851
+ async function drainOfflineDispatches(apiUrl, deviceId, secret, db, onEnqueued, isAlive) {
33852
+ if (!isAlive())
33853
+ return;
33852
33854
  let list;
33853
33855
  try {
33854
33856
  list = await apiClient.get(`${apiUrl}/api/devices/${deviceId}/dispatches/pending`);
@@ -33861,6 +33863,10 @@ async function drainOfflineDispatches(apiUrl, deviceId, secret, db, onEnqueued)
33861
33863
  return;
33862
33864
  log3(`\uD83E\uDEA3 draining ${rows.length} offline dispatch(es)`);
33863
33865
  for (const r of rows) {
33866
+ if (!isAlive()) {
33867
+ log3("drain aborted: shutting down");
33868
+ return;
33869
+ }
33864
33870
  try {
33865
33871
  const res = await fetch(`${apiUrl}/api/issues/dispatches/${r.id}/claim`, {
33866
33872
  method: "POST",
@@ -34368,7 +34374,10 @@ function loadConfig() {
34368
34374
  try {
34369
34375
  if (!existsSync7(CONFIG_PATH2))
34370
34376
  return {};
34371
- return JSON.parse(readFileSync7(CONFIG_PATH2, "utf8"));
34377
+ const raw = JSON.parse(readFileSync7(CONFIG_PATH2, "utf8"));
34378
+ if (!raw.token && raw.authToken)
34379
+ raw.token = raw.authToken;
34380
+ return raw;
34372
34381
  } catch {
34373
34382
  return {};
34374
34383
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipers-dev/multi",
3
- "version": "0.23.1",
3
+ "version": "0.23.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "multi-agent": "./dist/index.js"