@aikirun/workflow 0.8.0 → 0.9.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.d.ts +1 -0
- package/dist/index.js +21 -28
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -281,6 +281,7 @@ declare class WorkflowVersionImpl<Input, Output, AppContext, TEventsDefinition e
|
|
|
281
281
|
private handler;
|
|
282
282
|
private tryExecuteWorkflow;
|
|
283
283
|
private assertRetryAllowed;
|
|
284
|
+
private parse;
|
|
284
285
|
private createFailedState;
|
|
285
286
|
private createAwaitingRetryState;
|
|
286
287
|
}
|
package/dist/index.js
CHANGED
|
@@ -878,19 +878,7 @@ var WorkflowVersionImpl = class _WorkflowVersionImpl {
|
|
|
878
878
|
parentRunHandle[INTERNAL5].assertExecutionAllowed();
|
|
879
879
|
const { client } = parentRunHandle[INTERNAL5];
|
|
880
880
|
const inputRaw = isNonEmptyArray(args) ? args[0] : void 0;
|
|
881
|
-
|
|
882
|
-
if (this.params.schema?.input) {
|
|
883
|
-
try {
|
|
884
|
-
input = this.params.schema.input.parse(inputRaw);
|
|
885
|
-
} catch (error) {
|
|
886
|
-
await parentRunHandle[INTERNAL5].transitionState({
|
|
887
|
-
status: "failed",
|
|
888
|
-
cause: "self",
|
|
889
|
-
error: createSerializableError(error)
|
|
890
|
-
});
|
|
891
|
-
throw new WorkflowRunFailedError2(parentRun.id, parentRunHandle.run.attempts);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
881
|
+
const input = await this.parse(parentRunHandle, this.params.schema?.input, inputRaw);
|
|
894
882
|
const inputHash = await hashInput(input);
|
|
895
883
|
const reference = this.params.opts?.reference;
|
|
896
884
|
const path = getWorkflowRunPath(this.name, this.versionId, reference?.id ?? inputHash);
|
|
@@ -904,6 +892,9 @@ var WorkflowVersionImpl = class _WorkflowVersionImpl {
|
|
|
904
892
|
parentRun.logger
|
|
905
893
|
);
|
|
906
894
|
const { run: existingRun } = await client.api.workflowRun.getByIdV1({ id: existingRunInfo.id });
|
|
895
|
+
if (existingRun.state.status === "completed") {
|
|
896
|
+
await this.parse(parentRunHandle, this.params.schema?.output, existingRun.state.output);
|
|
897
|
+
}
|
|
907
898
|
const logger2 = parentRun.logger.child({
|
|
908
899
|
"aiki.childWorkflowName": existingRun.name,
|
|
909
900
|
"aiki.childWorkflowVersionId": existingRun.versionId,
|
|
@@ -985,29 +976,16 @@ var WorkflowVersionImpl = class _WorkflowVersionImpl {
|
|
|
985
976
|
logger.info("Workflow complete");
|
|
986
977
|
}
|
|
987
978
|
async tryExecuteWorkflow(input, run, context, retryStrategy) {
|
|
979
|
+
const { handle } = run[INTERNAL5];
|
|
988
980
|
while (true) {
|
|
989
981
|
try {
|
|
990
982
|
const outputRaw = await this.params.handler(run, input, context);
|
|
991
|
-
|
|
992
|
-
if (this.params.schema?.output) {
|
|
993
|
-
try {
|
|
994
|
-
output = this.params.schema.output.parse(outputRaw);
|
|
995
|
-
} catch (error) {
|
|
996
|
-
const { handle } = run[INTERNAL5];
|
|
997
|
-
await handle[INTERNAL5].transitionState({
|
|
998
|
-
status: "failed",
|
|
999
|
-
cause: "self",
|
|
1000
|
-
error: createSerializableError(error)
|
|
1001
|
-
});
|
|
1002
|
-
throw new WorkflowRunFailedError2(run.id, handle.run.attempts);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
983
|
+
const output = await this.parse(handle, this.params.schema?.output, outputRaw);
|
|
1005
984
|
return output;
|
|
1006
985
|
} catch (error) {
|
|
1007
986
|
if (error instanceof WorkflowRunSuspendedError4 || error instanceof WorkflowRunFailedError2 || error instanceof WorkflowRunConflictError5) {
|
|
1008
987
|
throw error;
|
|
1009
988
|
}
|
|
1010
|
-
const { handle } = run[INTERNAL5];
|
|
1011
989
|
const attempts = handle.run.attempts;
|
|
1012
990
|
const retryParams = getRetryParams(attempts, retryStrategy);
|
|
1013
991
|
if (!retryParams.retriesLeft) {
|
|
@@ -1052,6 +1030,21 @@ var WorkflowVersionImpl = class _WorkflowVersionImpl {
|
|
|
1052
1030
|
throw error;
|
|
1053
1031
|
}
|
|
1054
1032
|
}
|
|
1033
|
+
async parse(handle, schema, data) {
|
|
1034
|
+
if (!schema) {
|
|
1035
|
+
return data;
|
|
1036
|
+
}
|
|
1037
|
+
try {
|
|
1038
|
+
return schema.parse(data);
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
await handle[INTERNAL5].transitionState({
|
|
1041
|
+
status: "failed",
|
|
1042
|
+
cause: "self",
|
|
1043
|
+
error: createSerializableError(error)
|
|
1044
|
+
});
|
|
1045
|
+
throw new WorkflowRunFailedError2(handle.run.id, handle.run.attempts);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1055
1048
|
createFailedState(error) {
|
|
1056
1049
|
if (error instanceof TaskFailedError) {
|
|
1057
1050
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikirun/workflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Workflow SDK for Aiki - define durable workflows with tasks, sleeps, waits, and event handling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"build": "tsup"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@aikirun/types": "0.
|
|
21
|
+
"@aikirun/types": "0.9.0"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|