Retention
This section explains the Retention feature and how it can be used to remove completed workflow instances automatically.
Configuration
elsa.UseRetention(r =>
{
r.SweepInterval = TimeSpan.FromMinutes(30);
r.AddDeletePolicy("Delete all finished workflows", _ => new RetentionWorkflowInstanceFilter()
{
WorkflowStatus = WorkflowStatus.Finished
});
});Example
elsa.UseRetention(r =>
{
r.SweepInterval = TimeSpan.FromSeconds(30);
r.AddDeletePolicy("Delete all finished workflows", sp =>
{
ISystemClock clock = sp.GetRequiredService<ISystemClock>();
DateTimeOffset threshold = clock.UtcNow.Subtract(TimeSpan.FromHours(1));
return new RetentionWorkflowInstanceFilter()
{
TimestampFilters =
[
new TimestampFilter()
{
Column = nameof(WorkflowInstance.FinishedAt),
Operator = TimestampFilterOperator.LessThanOrEqual,
Timestamp = threshold
}
],
WorkflowStatus = WorkflowStatus.Finished
};
});
});Extending
Extra Entities
Entity Collector
Cleanup Strategy
Register Dependencies
Different Cleanup Strategies
Defining a Marker Interface
Defining the Policy
Implementing the Strategy
Last updated