danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.31k stars 1.19k forks source link

[Question] Best practices for handling events and error reporting in ASP.NET Core Web API #1275

Open santhanuv opened 2 months ago

santhanuv commented 2 months ago

Hi,

I'm using WorkflowCore in an ASP.NET Core Web API backend and calling publishEvent from a controller. Since the event is processed by the workflow as a background task, I'm unsure what response to return from the controller.

All our steps are short and should finish quickly, so I'm considering whether solutions like polling, long polling, or WebSockets are necessary.

If I send a generic 200 OK response after publishing the event and an error occurs during the execution of a step, how can I inform the front end about this issue? I'm using Angular on the front end and would like to handle this scenario effectively.

[HttpPost("publish-event")]
public async Task<IActionResult> PublishEvent([FromBody] EventModel model)
{
    await _workflowHost.PublishEvent(model.EventName, model.EventKey, model.EventData);
    return Ok();
}

Thanks!

slogsdon7 commented 1 month ago

I'd definitely return a 200 from that controller if the event published successfully. For dealing with step errors you can either query the status using the DbContext or use WFC's lifecycle events to handle errors more reactively.

santhanuv commented 1 week ago

Thank you for your response, and I apologize for the long delay in getting back to you. Just to update you, we're currently sending a 200 OK status from the controller.