@develit-services/bank 5.5.0 → 5.5.1
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/dist/base.cjs +21 -2
- package/dist/base.mjs +21 -2
- package/package.json +1 -1
package/dist/base.cjs
CHANGED
|
@@ -73,6 +73,25 @@ async function heartbeatSyncWorkflows({
|
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
const FINITE_STATUSES = /* @__PURE__ */ new Set([
|
|
77
|
+
"complete",
|
|
78
|
+
"errored",
|
|
79
|
+
"terminated"
|
|
80
|
+
]);
|
|
81
|
+
async function terminateSyncWorkflow(instance) {
|
|
82
|
+
const { status } = await instance.status();
|
|
83
|
+
if (FINITE_STATUSES.has(status)) return;
|
|
84
|
+
try {
|
|
85
|
+
await instance.terminate();
|
|
86
|
+
} catch (err) {
|
|
87
|
+
if (!isAlreadyFiniteError(err)) throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function isAlreadyFiniteError(err) {
|
|
91
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
92
|
+
return /cannot_terminate|finite state/i.test(message);
|
|
93
|
+
}
|
|
94
|
+
|
|
76
95
|
const upsertAccountCommand = (db, { account }) => {
|
|
77
96
|
const id = account.id || backendSdk.uuidv4();
|
|
78
97
|
const { id: _id, ...accountWithoutId } = account;
|
|
@@ -871,7 +890,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
871
890
|
{ successMessage: "Account sync workflow terminated" },
|
|
872
891
|
async ({ accountId }) => {
|
|
873
892
|
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
|
|
874
|
-
await instance
|
|
893
|
+
await terminateSyncWorkflow(instance);
|
|
875
894
|
return {
|
|
876
895
|
instanceId: instance.id
|
|
877
896
|
};
|
|
@@ -1934,7 +1953,7 @@ exports.BankServiceBase = class BankServiceBase extends backendSdk.develitWorker
|
|
|
1934
1953
|
}
|
|
1935
1954
|
try {
|
|
1936
1955
|
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
|
|
1937
|
-
await instance
|
|
1956
|
+
await terminateSyncWorkflow(instance);
|
|
1938
1957
|
} catch (error) {
|
|
1939
1958
|
this.log({
|
|
1940
1959
|
message: "No workflow instance found for account, skipping termination.",
|
package/dist/base.mjs
CHANGED
|
@@ -71,6 +71,25 @@ async function heartbeatSyncWorkflows({
|
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const FINITE_STATUSES = /* @__PURE__ */ new Set([
|
|
75
|
+
"complete",
|
|
76
|
+
"errored",
|
|
77
|
+
"terminated"
|
|
78
|
+
]);
|
|
79
|
+
async function terminateSyncWorkflow(instance) {
|
|
80
|
+
const { status } = await instance.status();
|
|
81
|
+
if (FINITE_STATUSES.has(status)) return;
|
|
82
|
+
try {
|
|
83
|
+
await instance.terminate();
|
|
84
|
+
} catch (err) {
|
|
85
|
+
if (!isAlreadyFiniteError(err)) throw err;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function isAlreadyFiniteError(err) {
|
|
89
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
90
|
+
return /cannot_terminate|finite state/i.test(message);
|
|
91
|
+
}
|
|
92
|
+
|
|
74
93
|
const upsertAccountCommand = (db, { account }) => {
|
|
75
94
|
const id = account.id || uuidv4();
|
|
76
95
|
const { id: _id, ...accountWithoutId } = account;
|
|
@@ -869,7 +888,7 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
869
888
|
{ successMessage: "Account sync workflow terminated" },
|
|
870
889
|
async ({ accountId }) => {
|
|
871
890
|
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
|
|
872
|
-
await instance
|
|
891
|
+
await terminateSyncWorkflow(instance);
|
|
873
892
|
return {
|
|
874
893
|
instanceId: instance.id
|
|
875
894
|
};
|
|
@@ -1932,7 +1951,7 @@ let BankServiceBase = class extends develitWorker(WorkerEntrypoint) {
|
|
|
1932
1951
|
}
|
|
1933
1952
|
try {
|
|
1934
1953
|
const instance = await this.env.SYNC_ACCOUNT_PAYMENTS_WORKFLOW.get(accountId);
|
|
1935
|
-
await instance
|
|
1954
|
+
await terminateSyncWorkflow(instance);
|
|
1936
1955
|
} catch (error) {
|
|
1937
1956
|
this.log({
|
|
1938
1957
|
message: "No workflow instance found for account, skipping termination.",
|