elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs.Persistence.Relational/Services/StructuredLogWriteBufferBackgroundTask.cs
Sipke Schoorstra 0687b5f9f3
Fix SQLite structured log shell lifecycle (#7461)
* Fix SQLite structured log shell lifecycle

* Address Greptile lifecycle feedback

* Tighten structured log lifecycle guards

* Address structured log background task review
2026-05-18 01:04:04 +02:00

32 lines
774 B
C#

using Elsa.Common;
namespace Elsa.Diagnostics.StructuredLogs.Persistence.Relational.Services;
public class StructuredLogWriteBufferBackgroundTask(StructuredLogWriteBuffer writeBuffer) : IBackgroundTask
{
private volatile bool _started;
public async Task StartAsync(CancellationToken cancellationToken)
{
if (_started)
return;
await writeBuffer.StartAsync(cancellationToken);
_started = true;
}
public Task ExecuteAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
if (!_started)
return;
_started = false;
await writeBuffer.StopAsync(cancellationToken);
}
}