@shipers-dev/multi 0.23.1 → 0.23.2

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 +12 -6
  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.2",
15004
15004
  type: "module",
15005
15005
  bin: {
15006
15006
  "multi-agent": "./dist/index.js"
@@ -32698,9 +32698,9 @@ async function cmdConnect(apiUrl, config2) {
32698
32698
  {
32699
32699
  const pending3 = await heartbeat();
32700
32700
  if (pending3 > 0)
32701
- drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2());
32701
+ drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2(), () => alive);
32702
32702
  }
32703
- drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2());
32703
+ drainOfflineDispatches(apiUrl, config2.deviceId, config2.token, db, () => schedule2(), () => alive);
32704
32704
  let alive = true;
32705
32705
  const shutdown = async (reason) => {
32706
32706
  if (!alive)
@@ -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
  }
@@ -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",
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.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "multi-agent": "./dist/index.js"