-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
- I can start work flow host in web api main program by call
app.StartHost()method:
var builder = WebApplication.CreateBuilder(args);
Log.Information("Starting web host");
var app = builder.Build();
try
{
app.StartHost();
app.Run();
}
finally
{
Log.CloseAndFlush();
}
- StartHost method implemnts:
public static WebApplication StartHost(this WebApplication app)
{
var services = app.Services;
var log = app.Services.GetRequiredService<ILoggerFactory>().CreateLogger("WorkflowStartup");
var registry = services.GetService<IWorkflowRegistry>();
var host = app.Services.GetRequiredService<IWorkflowHost>();
if (registry is not null && !registry.IsRegistered(nameof(StartWorkflow), 1))
{
host.RegisterWorkflow<StartWorkflow, WorkflowData<string>>();
host.RegisterWorkflow<PauseWorkflow, PauseWorkflowData>();
log.LogInformation("Registered Workflow ");
}
LifeCycleEventHandler lifeCycleHandler = async evt =>
{
try
{
if (evt is WorkflowCore.Models.LifeCycleEvents.WorkflowError stepErr)
{
log.LogError(
"Workflow {Id} step {StepId} error: {Message}",
stepErr.WorkflowInstanceId,
stepErr.StepId,
stepErr.Message
);
var z = host.PersistenceStore;
await host.TerminateWorkflow(evt.WorkflowInstanceId);
}
}
catch
{
log.LogError("Error handling life cycle event");
}
};
host.OnLifeCycleEvent += lifeCycleHandler;
log.LogInformation("Starting WorkflowCore host...");
host.Start();
app.Lifetime.ApplicationStopping.Register(() =>
{
host.OnLifeCycleEvent -= lifeCycleHandler;
host.Stop();
});
- i can start the work flow in the service from DI container as below
var workflowId = await host.StartWorkflow(
nameof(StartWorkflow),
new JobWorkflowData<string>()
);
Question:
The host and work flow started normally. it is expected action that when error occurs ,then the workflow was terminated, then i can start the work flow again.
But i found that the inner instances of host persistenceStore are added after per work flow terminated , i have a bit worry about the memory will up with time passes, I want to know how to clear terminated history workflow instances?
below is the memory snapshot ( inner instances of host persistenceStore):

Metadata
Metadata
Assignees
Labels
No labels