workflow-core
workflow-core copied to clipboard
Workflow host Publish Event - Get specific execution pointer for comparing with Step Completed Life Cycle Event
Is your feature request related to a problem? Please describe.
I have some workflow steps that should trigger an event/delegate back to a UI to display data that has been processed instead of polling for the data which can get costly. Is there an easy way to do this?
Describe the solution you'd like
Some of my workflow steps need to ping back to my UI to refresh so that data can be seen. I would like a way to know when a specific step has completed from a PublishEvent
Sort of something like this:
public string EventDrivenExecutionPointerId { get; set; }
// Blazor OnInitializedAsync
workflowHost.OnLifeCycleEvent += lifeCycleEvent =>
{
logger.LogInformation("Life cycle event: {@LifeCycleEvent}", lifeCycleEvent);
if (lifeCycleEvent is StepCompleted stepCompleted && stepCompleted.ExecutionPointerId == EventDrivenExecutionPointerId)
{
// Blazor UI Update
StateHasChanged();
}
};
EventDrivenExecutionPointerId = await workflowHost.PublishEvent("MyEvent", "0", "hello"); // wfc.ExecutionPointer.Id (GUID)
Describe alternatives you've considered
- Tried passing an
Actiondelegate to myTSettingsforIWorkflow<TSettings>- Causes NewtonSoft JSON.Net self reference loop error
- Using a Scoped DI service
- Workflow steps do not pickup the scoped configured service that was instantiated on page initialize
- Subscribe to
WorkflowHost.OnLifeCycleEvent- Not sure how to filter for the specific ExecutionPointerId of the step I am waiting for completion
Additional context
- MSSQL persistence
I was able to get this to work by polling the specific event execution pointer:
_workflowStepChecker = Task.Run(async () =>
{
while (true)
{
var workflowInstance = await PersistenceProvider.GetWorkflowInstance(_job.WorkflowInstanceId);
var executionPointer = workflowInstance.ExecutionPointers.Find(x => x.EventName == Constants.JobDataConfigurationUploadEvent);
if (executionPointer.Status == PointerStatus.Complete) break;
await Task.Delay(2000);
}
_workflowFilesExist = true;
await InvokeAsync(StateHasChanged);
});
Is there a better way to achieve this?