-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement execution logging for workflows #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,23 +29,75 @@ execRouter.post('/node', userMiddleware, async(req: AuthRequest, res: Response) | |||||||||
| if(nodeData){ | ||||||||||
| const type = nodeData.AvailableNode.type | ||||||||||
| const config = dataSafe.data.Config ? dataSafe.data.Config : nodeData.config // for test api data prefered fist then config in db | ||||||||||
| console.log(`config and type: ${JSON.stringify(config)} & ${type}`) | ||||||||||
| // // console.log(`config and type: ${JSON.stringify(config)} & ${type}`) | ||||||||||
|
|
||||||||||
| const context = { | ||||||||||
| userId: req.user.sub, | ||||||||||
| config: config, | ||||||||||
| credentialId: nodeData.CredentialsID || config?.credentialId || "" | ||||||||||
| } | ||||||||||
|
|
||||||||||
| console.log(`Execution context: ${JSON.stringify(context)}`) | ||||||||||
| const executionResult = await ExecutionRegister.execute(type, context) | ||||||||||
|
|
||||||||||
| console.log(`Execution result: ${executionResult}`) | ||||||||||
|
|
||||||||||
| if(executionResult.success) | ||||||||||
| return res.status(statusCodes.ACCEPTED).json({ | ||||||||||
| message: `${nodeData.name} node execution done` , | ||||||||||
| data: executionResult | ||||||||||
| const result = await prismaClient.$transaction(async(tx)=>{ | ||||||||||
| // // console.log(`Execution context: ${JSON.stringify(context)}`) | ||||||||||
| const workflowExecution = await tx.workflowExecution.create({ | ||||||||||
| data:{ | ||||||||||
| workflowId: nodeData.workflowId || "", | ||||||||||
| status: "Start", | ||||||||||
| startAt: new Date(), | ||||||||||
| metadata:{"isTesting": true}, | ||||||||||
| } | ||||||||||
| }) | ||||||||||
| const NodeExecution = await tx.nodeExecution.create({ | ||||||||||
| data:{ | ||||||||||
| status: "Start", | ||||||||||
| nodeId: nodeData.id, | ||||||||||
| workflowExecId: workflowExecution.id, | ||||||||||
| startedAt: new Date(), | ||||||||||
| inputData: context, | ||||||||||
| isTest: true | ||||||||||
| } | ||||||||||
| }) | ||||||||||
| const executionResult = await ExecutionRegister.execute(type, context) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| // console.log(`Execution result: ${executionResult}`) | ||||||||||
|
|
||||||||||
| if(executionResult.success){ | ||||||||||
| await tx.nodeExecution.update({ | ||||||||||
| where: { id: NodeExecution.id}, | ||||||||||
| data:{ | ||||||||||
| status: "Completed", | ||||||||||
| outputData: executionResult.output, | ||||||||||
| completedAt: new Date() | ||||||||||
| } | ||||||||||
| }) | ||||||||||
| await tx.workflowExecution.update({ | ||||||||||
| where: {id: workflowExecution.id}, | ||||||||||
| data: { | ||||||||||
| status: "Completed", | ||||||||||
| completedAt: new Date() | ||||||||||
| } | ||||||||||
| }) | ||||||||||
| return res.status(statusCodes.ACCEPTED).json({ | ||||||||||
| message: `${nodeData.name} node execution done` , | ||||||||||
| data: executionResult | ||||||||||
| }) | ||||||||||
| } | ||||||||||
| await tx.nodeExecution.update({ | ||||||||||
| where: {id : NodeExecution.id}, | ||||||||||
| data:{ | ||||||||||
| status: "Failed", | ||||||||||
| completedAt: new Date(), | ||||||||||
| error: executionResult.error | ||||||||||
| } | ||||||||||
| }) | ||||||||||
| await tx.workflowExecution.update({ | ||||||||||
| where: {id: workflowExecution.id}, | ||||||||||
| data:{ | ||||||||||
| status: "Failed", | ||||||||||
| completedAt: new Date(), | ||||||||||
| error: executionResult.output | ||||||||||
|
||||||||||
| error: executionResult.output | |
| error: typeof executionResult.error === "string" | |
| ? executionResult.error | |
| : JSON.stringify(executionResult.error ?? executionResult.output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The route sends an HTTP response from inside the Prisma $transaction callback, then execution continues after the transaction and a second response is sent (the 403 at the end). This will trigger “headers already sent” and can leave the transaction in an unclear state. Refactor to have the transaction return data/status (or throw), then send exactly one res.status(...).json(...) after the transaction resolves.