< Summary

Information
Class: Elsa.Workflows.Runtime.HeartbeatGenerator
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/HeartbeatGenerator.cs
Line coverage
50%
Covered lines: 8
Uncovered lines: 8
Coverable lines: 16
Total lines: 38
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GenerateHeartbeatAsync()100%210%
Dispose()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/HeartbeatGenerator.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2
 3namespace Elsa.Workflows.Runtime;
 4
 5public class HeartbeatGenerator : IDisposable
 6{
 7    private readonly Timer _timer;
 8    private readonly Func<Task> _heartbeatAction;
 9    private readonly TimeSpan _interval;
 10    private readonly ILogger<HeartbeatGenerator> _logger;
 11
 47412    public HeartbeatGenerator(Func<Task> heartbeatAction, TimeSpan interval, ILoggerFactory loggerFactory)
 13    {
 47414        _heartbeatAction = heartbeatAction;
 47415        _interval = interval;
 47416        _logger = loggerFactory.CreateLogger<HeartbeatGenerator>();
 47417        _timer = new(GenerateHeartbeatAsync, null, _interval, Timeout.InfiniteTimeSpan);
 47418    }
 19
 20    private async void GenerateHeartbeatAsync(object? state)
 21    {
 22        try
 23        {
 024            _logger.LogDebug("Generating heartbeat");
 025            await _heartbeatAction();
 026            _timer.Change(_interval, Timeout.InfiniteTimeSpan);
 027        }
 028        catch (Exception ex)
 29        {
 030            _logger.LogError(ex, "An error occurred while generating a workflow heartbeat.");
 031        }
 032    }
 33
 34    public void Dispose()
 35    {
 47436        _timer.Dispose();
 47437    }
 38}