< Summary

Information
Class: Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Services.SqliteStructuredLogStartupService
Assembly: Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite/Services/SqliteStructuredLogStartupService.cs
Line coverage
89%
Covered lines: 17
Uncovered lines: 2
Coverable lines: 19
Total lines: 46
Line coverage: 89.4%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
StartAsync()100%11100%
ExecuteAsync()75%8881.81%
StopAsync(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite/Services/SqliteStructuredLogStartupService.cs

#LineLine coverage
 1using Elsa.Common;
 2using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Contracts;
 3using Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Services;
 4using Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Options;
 5using Microsoft.Extensions.Hosting;
 6using Microsoft.Extensions.Options;
 7
 8namespace Elsa.Diagnostics.StructuredLogs.Persistence.Sqlite.Services;
 9
 810public class SqliteStructuredLogStartupService(
 811    IStructuredLogSchemaMigrator schemaMigrator,
 812    StructuredLogRetentionService retentionService,
 813    IOptions<SqliteStructuredLogOptions> options) : IHostedService, IStartupTask
 14{
 815    private readonly SemaphoreSlim _startupLock = new(1, 1);
 16    private bool _executed;
 17
 18    public async Task StartAsync(CancellationToken cancellationToken)
 19    {
 420        await ExecuteAsync(cancellationToken);
 421    }
 22
 23    public async Task ExecuteAsync(CancellationToken cancellationToken)
 24    {
 625        await _startupLock.WaitAsync(cancellationToken);
 26        try
 27        {
 628            if (_executed)
 029                return;
 30
 631            if (options.Value.RunMigrationsOnStartup)
 532                await schemaMigrator.MigrateAsync(cancellationToken);
 33
 634            if (options.Value.Relational.Retention.CleanupOnStartup)
 035                await retentionService.CleanupAsync(cancellationToken);
 36
 637            _executed = true;
 638        }
 39        finally
 40        {
 641            _startupLock.Release();
 42        }
 643    }
 44
 345    public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
 46}