| | | 1 | | using Elsa.Common; |
| | | 2 | | using Elsa.Workflows.Management; |
| | | 3 | | using Elsa.Workflows.Runtime.Middleware.Workflows; |
| | | 4 | | using Elsa.Workflows.Runtime.Options; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Runtime; |
| | | 9 | | |
| | 436 | 10 | | public class WorkflowHeartbeatGeneratorFactory(IOptions<RuntimeOptions> options, ISystemClock systemClock, ILogger<Workf |
| | | 11 | | { |
| | | 12 | | public HeartbeatGenerator CreateHeartbeatGenerator(WorkflowExecutionContext context) |
| | | 13 | | { |
| | 474 | 14 | | var inactivityThreshold = options.Value.InactivityThreshold; |
| | 474 | 15 | | var heartbeatInterval = TimeSpan.FromTicks((long)(inactivityThreshold.Ticks * 0.6)); |
| | 474 | 16 | | logger.LogDebug("Workflow heartbeat interval: {Interval}", heartbeatInterval); |
| | 474 | 17 | | return new(async () => await UpdateTimestampAsync(context), heartbeatInterval, loggerFactory); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | private async Task UpdateTimestampAsync(WorkflowExecutionContext context) |
| | | 21 | | { |
| | 0 | 22 | | var workflowInstanceStore = context.GetRequiredService<IWorkflowInstanceStore>(); |
| | 0 | 23 | | var workflowInstanceId = context.Id; |
| | 0 | 24 | | await workflowInstanceStore.UpdateUpdatedTimestampAsync(workflowInstanceId, systemClock.UtcNow, context.Cancella |
| | 0 | 25 | | } |
| | | 26 | | } |