Skip to content

Commit 2757156

Browse files
committed
check generation number before logging or marking other failures
1 parent a897666 commit 2757156

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/component/pool.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ export const onComplete = internalMutation({
8686
assert(journalEntry, `Journal entry not found: ${stepId}`);
8787
const workflowId = journalEntry.workflowId;
8888

89-
const error = !validate(onCompleteContext, args.context)
90-
? `Invalid onComplete context for workId ${args.workId}` +
91-
JSON.stringify(args.context)
92-
: !journalEntry.step.inProgress
93-
? `Journal entry not in progress: ${stepId}`
94-
: undefined;
95-
if (error) {
89+
if (
90+
!validate(onCompleteContext, args.context, { allowUnknownFields: true })
91+
) {
92+
const error =
93+
`Invalid onComplete context for workId ${args.workId}` +
94+
JSON.stringify(args.context);
9695
await ctx.db.patch(workflowId, {
9796
runResult: {
9897
kind: "failed",
@@ -101,7 +100,20 @@ export const onComplete = internalMutation({
101100
});
102101
return;
103102
}
103+
const { generationNumber } = args.context;
104104
const workflow = await getWorkflow(ctx, workflowId, null);
105+
if (workflow.generationNumber !== generationNumber) {
106+
console.error(
107+
`Workflow: ${workflowId} already has generation number ${workflow.generationNumber} when completing ${stepId}`,
108+
);
109+
return;
110+
}
111+
if (!journalEntry.step.inProgress) {
112+
console.error(
113+
`Step finished but journal entry not in progress: ${stepId} status: ${journalEntry.step.runResult?.kind ?? "pending"}`,
114+
);
115+
return;
116+
}
105117
if (
106118
journalEntry.step.functionType === "pause" &&
107119
args.result.kind === "success"
@@ -154,13 +166,6 @@ export const onComplete = internalMutation({
154166
}
155167
return;
156168
}
157-
const { generationNumber } = args.context;
158-
if (workflow.generationNumber !== generationNumber) {
159-
console.error(
160-
`Workflow: ${workflowId} already has generation number ${workflow.generationNumber} when completing ${stepId}`,
161-
);
162-
return;
163-
}
164169
const workpool = await getWorkpool(ctx, args.context.workpoolOptions);
165170
await workpool.enqueueMutation(
166171
ctx,

0 commit comments

Comments
 (0)