< Summary

Information
Class: Elsa.Workflows.Runtime.Tasks.RestartInterruptedWorkflowsTask
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Tasks/RestartInterruptedWorkflowsTask.cs
Line coverage
95%
Covered lines: 21
Uncovered lines: 1
Coverable lines: 22
Total lines: 47
Line coverage: 95.4%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteAsync()50%2287.5%
CreateWorkflowInstanceFilter()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Tasks/RestartInterruptedWorkflowsTask.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Common.RecurringTasks;
 3using Elsa.Workflows.Management;
 4using Elsa.Workflows.Management.Filters;
 5using Elsa.Workflows.Runtime.Options;
 6using JetBrains.Annotations;
 7using Microsoft.Extensions.Logging;
 8using Microsoft.Extensions.Options;
 9
 10namespace Elsa.Workflows.Runtime.Tasks;
 11
 12[SingleNodeTask]
 13[UsedImplicitly]
 514public class RestartInterruptedWorkflowsTask(
 515    IWorkflowInstanceStore workflowInstanceStore,
 516    IWorkflowRestarter workflowRestarter,
 517    IOptions<RuntimeOptions> options,
 518    ISystemClock systemClock,
 519    ILogger<RestartInterruptedWorkflowsTask> logger) : RecurringTask
 20{
 21    /// <inheritdoc />
 22    public override async Task ExecuteAsync(CancellationToken cancellationToken)
 23    {
 224        var workflowInstanceFilter = CreateWorkflowInstanceFilter();
 225        var batchSize = options.Value.RestartInterruptedWorkflowsBatchSize;
 226        var workflowInstances = workflowInstanceStore.EnumerateSummariesAsync(workflowInstanceFilter, batchSize, cancell
 27
 228        logger.LogInformation("Restarting interrupted workflows.");
 429        await foreach (var workflowInstance in workflowInstances)
 30        {
 031            await workflowRestarter.RestartWorkflowAsync(workflowInstance.Id, cancellationToken: cancellationToken);
 32        }
 233        logger.LogInformation("Finished restarting interrupted workflows.");
 234    }
 35
 36    private WorkflowInstanceFilter CreateWorkflowInstanceFilter()
 37    {
 238        var livenessThreshold = options.Value.InactivityThreshold;
 239        var now = systemClock.UtcNow;
 240        var cutoffTimestamp = now - livenessThreshold;
 241        return new()
 242        {
 243            IsExecuting = true,
 244            BeforeLastUpdated = cutoffTimestamp
 245        };
 46    }
 47}