@withone/cli 1.37.1 → 1.37.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 +25 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5721,10 +5721,10 @@ async function syncModel(api, profile, options) {
5721
5721
  }
5722
5722
  const lock = options.dryRun ? null : acquireSyncLock(platform, model);
5723
5723
  const existingState = getModelState(platform, model);
5724
- if (existingState?.status === "syncing" && !options.force) {
5725
- if (lock) lock.release();
5726
- throw new Error(
5727
- `Sync state says ${platform}/${model} is already syncing. Use --force to override (this may happen if a previous sync crashed before cleanup).`
5724
+ if (existingState?.status === "syncing" && !options.dryRun && !isAgentMode()) {
5725
+ process.stderr.write(
5726
+ `Recovered from crashed previous sync of ${platform}/${model} (state was 'syncing', no live owner)
5727
+ `
5728
5728
  );
5729
5729
  }
5730
5730
  if (!profile.dateFilter && !options.dryRun && !options.fullRefresh && !isAgentMode()) {
@@ -5733,13 +5733,28 @@ async function syncModel(api, profile, options) {
5733
5733
  `
5734
5734
  );
5735
5735
  }
5736
- if (!options.dryRun) {
5737
- updateModelState(platform, model, { status: "syncing" });
5738
- }
5739
5736
  let db = null;
5740
5737
  let totalRecords = 0;
5741
5738
  let pagesProcessed = 0;
5742
5739
  let lastCursor = null;
5740
+ const signalCleanup = (signal) => {
5741
+ try {
5742
+ updateModelState(platform, model, { status: "failed", pagesProcessed, lastCursor });
5743
+ } catch {
5744
+ }
5745
+ try {
5746
+ if (lock) lock.release();
5747
+ } catch {
5748
+ }
5749
+ process.exit(signal === "SIGINT" ? 130 : 143);
5750
+ };
5751
+ const onSigint = () => signalCleanup("SIGINT");
5752
+ const onSigterm = () => signalCleanup("SIGTERM");
5753
+ if (!options.dryRun) {
5754
+ process.on("SIGINT", onSigint);
5755
+ process.on("SIGTERM", onSigterm);
5756
+ updateModelState(platform, model, { status: "syncing" });
5757
+ }
5743
5758
  const seenIds = /* @__PURE__ */ new Set();
5744
5759
  let hooksInserted = 0;
5745
5760
  let hooksUpdated = 0;
@@ -6102,6 +6117,9 @@ async function syncModel(api, profile, options) {
6102
6117
  wrapped._recordsSynced = totalRecords;
6103
6118
  wrapped._pagesProcessed = pagesProcessed;
6104
6119
  throw wrapped;
6120
+ } finally {
6121
+ process.off("SIGINT", onSigint);
6122
+ process.off("SIGTERM", onSigterm);
6105
6123
  }
6106
6124
  }
6107
6125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/cli",
3
- "version": "1.37.1",
3
+ "version": "1.37.2",
4
4
  "description": "CLI for managing One",
5
5
  "type": "module",
6
6
  "files": [