Comments (4)
Use saga pattern
https://workflow-core.readthedocs.io/en/latest/sagas/
from workflow-core.
@brucezlata Can you please let me know how I can implement saga transaction. I am using EventPublish to forward the workflow step and in each step i have perform some database transaction through service injection. if error raises on any step, it will suspend the workflow and rollback my service transaction for current step only.
from workflow-core.
@MOwaisfarooq you can check the above link, for example, throw exception once there is any error in any of your steps (Tasks), then, compensate entire saga transaction (UndoEverything).
builder
.StartWith(context => Console.WriteLine("Begin"))
.Saga(saga => saga
.StartWith<Task1>()
.Then<Task2>()
.Then<Task3>()
)
.CompensateWith<**UndoEverything**>()
.Then(context => Console.WriteLine("End"));
from workflow-core.
If an error occurs in step B of the workflow, I suspend the workflow to publish this event later from the controller API. The _workflowStepDetailsService.UpdateTransactionForStepB has made a transaction in my table stepTable. I want to revert only the step B service transaction that updated the table. I don't want to undo everything, so that next time I can continue from step B after the error. For example, if I made an insertion in step A using _workflowStepDetailsService.CreateTransactionforStepA in my stepTable, I want to preserve that transaction and only undo the changes made by step B.
builder .StartWith(context => Console.WriteLine("Begin")) .UseDefaultErrorBehavior(WorkflowErrorHandling.Suspend) .Saga(saga => saga .StartWith<stepA>() .Then<stepB>() .Then<stepC>() ) .CompensateWith<**UndoEverything**>() .Then(context => Console.WriteLine("End"));
``
public class stepA: StepBodyAsync
{
private readonly IWorkflowStepDetailsService _workflowStepDetailsService;
public stepA(IWorkflowStepDetailsService workflowStepDetailsService)
{
_workflowStepDetailsService = workflowStepDetailsService;
}
public override async Task<ExecutionResult> RunAsync(IStepExecutionContext context)
{
if (!context.ExecutionPointer.EventPublished)
{
return ExecutionResult.WaitForEvent("StartWorkflowEvent", context.Workflow.Id, DateTime.Now);
}
var workflowsteprequest = (WorkFlowStepDetails)context.ExecutionPointer.EventData;
await _workflowStepDetailsService.CreateTransactionforStepA(workflowsteprequest);
return ExecutionResult.Next();
}
}
``
public class stepB : StepBodyAsync
{
private readonly IWorkflowStepDetailsService _workflowStepDetailsService;
public stepB: (IWorkflowStepDetailsService workflowStepDetailsService)
{
_workflowStepDetailsService = workflowStepDetailsService;
}
public override async Task<ExecutionResult> RunAsync(IStepExecutionContext context)
{
if (!context.ExecutionPointer.EventPublished)
{
return ExecutionResult.WaitForEvent("StartWorkflowEvent", context.Workflow.Id, DateTime.Now);
}
var workflowsteprequest = (WorkFlowStepDetails)context.ExecutionPointer.EventData;
await _workflowStepDetailsService.UpdateTransactionForStepB(workflowsteprequest);
return ExecutionResult.Next();
}
}
``
from workflow-core.
Related Issues (20)
- How can I define UserTask using JSON file? HOT 1
- Parallel tasks run in sequence not parallel HOT 2
- What should I do if it is rejected to the specified node that has been executed
- Why can'not I use constructor function in workflow step function HOT 1
- Multiple processes are multi-threaded in parallel? HOT 1
- Can I use the library to implement a fallback mechanism?
- How to achieve exponential backoff retry policy HOT 1
- Facing issue to use Mongo as persistance storage HOT 2
- On wpf application workflow doesn't run at first HOT 3
- How to rollback service Transaction
- host.Start()启动后的host对象和从容器获取的IWorkflowHost对象不一样
- How to register workflows on every node with Multi-node clusters?
- Clear terminated workflow instances
- 7k requests a minute to azure blob storage
- Memory leak
- [Question] Would it be advisable to structure our process using sub-workflows? HOT 3
- Deserialisation in the ToWorkflowInstance() duplicates List items due to not set ObjectCreationHandling = ObjectCreationHandling.Replace in the JsonSerializerSettings
- [Question] How to break foreach loop?
- Is there any sample to use it on .NET framework?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workflow-core.