@aikirun/worker 0.20.0 → 0.22.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/dist/index.js +25 -41
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -674,7 +674,6 @@ function createEventMulticaster(workflowName, workflowVersionId, eventName, sche
|
|
|
674
674
|
// ../workflow/run/handle.ts
|
|
675
675
|
import { INTERNAL as INTERNAL3 } from "@aikirun/types/symbols";
|
|
676
676
|
import {
|
|
677
|
-
isTerminalWorkflowRunStatus,
|
|
678
677
|
WorkflowRunNotExecutableError,
|
|
679
678
|
WorkflowRunRevisionConflictError as WorkflowRunRevisionConflictError3
|
|
680
679
|
} from "@aikirun/types/workflow-run";
|
|
@@ -714,9 +713,6 @@ var WorkflowRunHandleImpl = class {
|
|
|
714
713
|
const { run: currentRun } = await this.api.workflowRun.getByIdV1({ id: this.run.id });
|
|
715
714
|
this._run = currentRun;
|
|
716
715
|
}
|
|
717
|
-
// TODO: instead checking the current state, use the transition history
|
|
718
|
-
// because it is possible for a workflow to flash though a state
|
|
719
|
-
// and the handle will never know that the workflow hit that state
|
|
720
716
|
async waitForStatus(status, options) {
|
|
721
717
|
return this.waitForStatusByPolling(status, options);
|
|
722
718
|
}
|
|
@@ -730,49 +726,37 @@ var WorkflowRunHandleImpl = class {
|
|
|
730
726
|
const delayMs = options?.interval ? toMilliseconds(options.interval) : 1e3;
|
|
731
727
|
const maxAttempts = options?.timeout ? Math.ceil(toMilliseconds(options.timeout) / delayMs) : Number.POSITIVE_INFINITY;
|
|
732
728
|
const retryStrategy = { type: "fixed", maxAttempts, delayMs };
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
729
|
+
const afterStateTransitionId = this._run.stateTransitionId;
|
|
730
|
+
const hasTerminated = async () => {
|
|
731
|
+
const { terminated } = await this.api.workflowRun.hasTerminatedV1({
|
|
732
|
+
id: this._run.id,
|
|
733
|
+
afterStateTransitionId
|
|
734
|
+
});
|
|
735
|
+
return terminated;
|
|
736
736
|
};
|
|
737
|
-
const
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
737
|
+
const shouldRetryOnResult = async (terminated) => !terminated;
|
|
738
|
+
const maybeResult = options?.abortSignal ? await withRetry(hasTerminated, retryStrategy, {
|
|
739
|
+
abortSignal: options.abortSignal,
|
|
740
|
+
shouldRetryOnResult
|
|
741
|
+
}).run() : await withRetry(hasTerminated, retryStrategy, { shouldRetryOnResult }).run();
|
|
742
|
+
if (maybeResult.state === "timeout") {
|
|
743
|
+
if (!Number.isFinite(maxAttempts)) {
|
|
743
744
|
throw new Error("Something's wrong, this should've never timed out");
|
|
744
745
|
}
|
|
745
|
-
|
|
746
|
-
return {
|
|
747
|
-
success: false,
|
|
748
|
-
cause: "run_terminated"
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
return {
|
|
752
|
-
success: true,
|
|
753
|
-
state: maybeResult2.result
|
|
754
|
-
};
|
|
746
|
+
return { success: false, cause: "timeout" };
|
|
755
747
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
this.logger.info("Maybe result", { maybeResult });
|
|
763
|
-
if (maybeResult.state === "completed") {
|
|
764
|
-
if (maybeResult.result.status !== expectedStatus) {
|
|
765
|
-
return {
|
|
766
|
-
success: false,
|
|
767
|
-
cause: "run_terminated"
|
|
768
|
-
};
|
|
769
|
-
}
|
|
748
|
+
if (maybeResult.state === "aborted") {
|
|
749
|
+
return { success: false, cause: "aborted" };
|
|
750
|
+
}
|
|
751
|
+
maybeResult.state;
|
|
752
|
+
await this.refresh();
|
|
753
|
+
if (this._run.state.status === expectedStatus) {
|
|
770
754
|
return {
|
|
771
755
|
success: true,
|
|
772
|
-
state:
|
|
756
|
+
state: this._run.state
|
|
773
757
|
};
|
|
774
758
|
}
|
|
775
|
-
return { success: false, cause:
|
|
759
|
+
return { success: false, cause: "run_terminated" };
|
|
776
760
|
}
|
|
777
761
|
async cancel(reason) {
|
|
778
762
|
await this.transitionState({ status: "cancelled", reason });
|
|
@@ -846,7 +830,7 @@ function isWorkflowRunRevisionConflictError(error) {
|
|
|
846
830
|
// ../workflow/run/handle-child.ts
|
|
847
831
|
import { INTERNAL as INTERNAL4 } from "@aikirun/types/symbols";
|
|
848
832
|
import {
|
|
849
|
-
isTerminalWorkflowRunStatus
|
|
833
|
+
isTerminalWorkflowRunStatus,
|
|
850
834
|
WorkflowRunRevisionConflictError as WorkflowRunRevisionConflictError4,
|
|
851
835
|
WorkflowRunSuspendedError as WorkflowRunSuspendedError3
|
|
852
836
|
} from "@aikirun/types/workflow-run";
|
|
@@ -894,7 +878,7 @@ function createStatusWaiter(handle, parentRun, childWorkflowRunWaitQueues, logge
|
|
|
894
878
|
state: existingChildWorkflowRunWait.childWorkflowRunState
|
|
895
879
|
};
|
|
896
880
|
}
|
|
897
|
-
if (
|
|
881
|
+
if (isTerminalWorkflowRunStatus(childWorkflowRunStatus)) {
|
|
898
882
|
logger.debug("Child workflow run reached termnial state", {
|
|
899
883
|
"aiki.childWorkflowTerminalStatus": childWorkflowRunStatus
|
|
900
884
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikirun/worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Worker SDK for Aiki - execute workflows and tasks with durable state management and automatic recovery",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"build": "tsup"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@aikirun/types": "0.
|
|
22
|
-
"@aikirun/client": "0.
|
|
23
|
-
"@aikirun/workflow": "0.
|
|
21
|
+
"@aikirun/types": "0.22.0",
|
|
22
|
+
"@aikirun/client": "0.22.0",
|
|
23
|
+
"@aikirun/workflow": "0.22.0",
|
|
24
24
|
"ulidx": "^2.4.1"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|