Skip to content
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

Workflow-Core: How to implement decision step and invoke from api #1304

Open
dbandyop005 opened this issue Sep 28, 2024 Discussed in #1151 · 0 comments
Open

Workflow-Core: How to implement decision step and invoke from api #1304

dbandyop005 opened this issue Sep 28, 2024 Discussed in #1151 · 0 comments

Comments

@dbandyop005
Copy link

Scenario: A product is created. A notification is sent to approver for approval. If approved/rejected it updates the product status in db. Trying to achieve this using Workflow-Core in .net application.

//Below is the builder:
public void Build(IWorkflowBuilder builder)
{
builder
.StartWith < **CreateProductStep * *> ()
.WaitFor("ApprovedProduct", (data, context) => data.ProductId)
.Then < **ApproveRejectStep * *> ();
}

//These are the workflow steps:
public class CreateProductStep : StepBody
{
public override ExecutionResult Run(IStepExecutionContext context)
{
var data = context.Workflow.Data as MyData;

    Console.WriteLine($"Product created {data.ProductId} {data.IsApproved}");
    return ExecutionResult.Next();
}

}

public class ApproveRejectStep : StepBody
{
public override ExecutionResult Run(IStepExecutionContext context)
{
var data = context.Workflow.Data as MyData;

    Console.WriteLine($"Product updated {data.ProductId} {data.IsApproved}");
    return ExecutionResult.Next();
}

}
//The Controller:

[HttpPost("addproduct")]
public async Task AddProduct([FromBody] MyData product)
{
var workflowId = await _workflowHost.StartWorkflow("ProductWorkflow1", product);
return Ok(new { WorkflowId = workflowId, Message = "Product added and workflow started." });
}
[HttpPost("approve-reject-product")]
public async Task ApproveRejectProduct([FromBody] MyData product)
{
await _workflowHost.PublishEvent("ApprovedProduct", product.ProductId, product);

return Ok(new { Message = $"Product {product.IsApproved}" });

}

Expecting the WaitFor to get the context of the first step:CreateProductStep and pass it to the next step:ApproveRejectStep. Which is not happening. What am I missing here. How can I achieve passing the context of the previous flow to the next waitfor step and invoke via api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant