From 037b82dc4942fef56e5b7b8ef7617fadea62b481 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sat, 22 Feb 2025 16:22:33 +0100 Subject: [PATCH] Update inactivity threshold and adjust related timings Renamed 'WorkflowLivenessThreshold' to 'InactivityThreshold' for clarity and updated its usage across affected files. Adjusted timings for workflow restarts and delays to improve consistency, including increasing task delay and updating scheduler intervals. These changes enhance readability and align with revised task execution timelines. --- src/apps/Elsa.Server.Web/Program.cs | 6 +++--- src/apps/Elsa.Server.Web/SlowActivity.cs | 2 +- .../Middleware/Workflows/HeartbeatMiddleware.cs | 2 +- .../Elsa.Workflows.Runtime/Options/RuntimeOptions.cs | 2 +- .../Tasks/RestartInterruptedWorkflowsTask.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apps/Elsa.Server.Web/Program.cs b/src/apps/Elsa.Server.Web/Program.cs index 0816171cd..6ce024b3f 100644 --- a/src/apps/Elsa.Server.Web/Program.cs +++ b/src/apps/Elsa.Server.Web/Program.cs @@ -681,13 +681,13 @@ services.Configure(options => options.Schedule.ConfigureTask(TimeSpan.FromSeconds(300)); options.Schedule.ConfigureTask(TimeSpan.FromSeconds(300)); options.Schedule.ConfigureTask(TimeSpan.FromHours(4)); - options.Schedule.ConfigureTask(TimeSpan.FromSeconds(15)); + options.Schedule.ConfigureTask(TimeSpan.FromMinutes(1)); }); -services.Configure(options => { options.WorkflowLivenessThreshold = TimeSpan.FromSeconds(15); }); +services.Configure(options => { options.InactivityThreshold = TimeSpan.FromMinutes(1); }); services.Configure(options => options.Ttl = TimeSpan.FromSeconds(10)); - services.Configure(options => options.CacheDuration = TimeSpan.FromDays(1)); + services.AddHealthChecks(); services.AddControllers(); services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("*"))); diff --git a/src/apps/Elsa.Server.Web/SlowActivity.cs b/src/apps/Elsa.Server.Web/SlowActivity.cs index 633fb2f00..54d562eb0 100644 --- a/src/apps/Elsa.Server.Web/SlowActivity.cs +++ b/src/apps/Elsa.Server.Web/SlowActivity.cs @@ -7,7 +7,7 @@ public class SlowActivity : CodeActivity protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) { Console.WriteLine("Starting..."); - await Task.Delay(TimeSpan.FromMinutes(1)); + await Task.Delay(TimeSpan.FromMinutes(2)); Console.WriteLine("Done."); } } \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Runtime/Middleware/Workflows/HeartbeatMiddleware.cs b/src/modules/Elsa.Workflows.Runtime/Middleware/Workflows/HeartbeatMiddleware.cs index ddba027b2..71a481f76 100644 --- a/src/modules/Elsa.Workflows.Runtime/Middleware/Workflows/HeartbeatMiddleware.cs +++ b/src/modules/Elsa.Workflows.Runtime/Middleware/Workflows/HeartbeatMiddleware.cs @@ -11,7 +11,7 @@ public class WorkflowHeartbeatMiddleware(WorkflowMiddlewareDelegate next, IOptio { public override async ValueTask InvokeAsync(WorkflowExecutionContext context) { - var livenessThreshold = options.Value.WorkflowLivenessThreshold; + var livenessThreshold = options.Value.InactivityThreshold; var heartbeatInterval = TimeSpan.FromTicks((long)(livenessThreshold.Ticks * 0.6)); logger.LogDebug("Workflow heartbeat interval: {Interval}", heartbeatInterval); using var heartbeat = new WorkflowHeartbeat(async () => await UpdateTimestampAsync(context), heartbeatInterval, loggerFactory); diff --git a/src/modules/Elsa.Workflows.Runtime/Options/RuntimeOptions.cs b/src/modules/Elsa.Workflows.Runtime/Options/RuntimeOptions.cs index 1eb7fcebf..b71dabb1b 100644 --- a/src/modules/Elsa.Workflows.Runtime/Options/RuntimeOptions.cs +++ b/src/modules/Elsa.Workflows.Runtime/Options/RuntimeOptions.cs @@ -21,7 +21,7 @@ public class RuntimeOptions /// A separate heartbeat process will ensure the is updated before this threshold. /// If the workflow instance got removed from memory, e.g. because of an application shutdown, the LastUpdated field will eventually exceed the liveness threshold and therefore be considered to be interrupted. /// - public TimeSpan WorkflowLivenessThreshold { get; set; } = TimeSpan.FromMinutes(5); + public TimeSpan InactivityThreshold { get; set; } = TimeSpan.FromMinutes(5); /// /// The number of workflow instances to restart in a single batch. diff --git a/src/modules/Elsa.Workflows.Runtime/Tasks/RestartInterruptedWorkflowsTask.cs b/src/modules/Elsa.Workflows.Runtime/Tasks/RestartInterruptedWorkflowsTask.cs index 7f5191e46..f645f56d4 100644 --- a/src/modules/Elsa.Workflows.Runtime/Tasks/RestartInterruptedWorkflowsTask.cs +++ b/src/modules/Elsa.Workflows.Runtime/Tasks/RestartInterruptedWorkflowsTask.cs @@ -35,7 +35,7 @@ public class RestartInterruptedWorkflowsTask( private WorkflowInstanceFilter CreateWorkflowInstanceFilter() { - var livenessThreshold = options.Value.WorkflowLivenessThreshold; + var livenessThreshold = options.Value.InactivityThreshold; var now = systemClock.UtcNow; var cutoffTimestamp = now - livenessThreshold; return new()