elsa-core/src/modules/Elsa.Workflows.Runtime/Services/BookmarkQueueSignaler.cs
Sipke Schoorstra a2448523a9
Fix race condition and add rate limiting to bookmark queue processing (#6187)
* Fix race condition and add rate limiting to bookmark queue processing

Introduce rate-limited function invocation for bookmark queue processing using ThrottleDebounce library to optimize performance. Update related classes and interfaces to support asynchronous and cancellation-aware operations, improving system responsiveness. Adjust logging to provide more detailed information during bookmark queue handling.

* Enable workflows on bug branches

This change updates the GitHub Actions workflow configuration to trigger on branches with the 'bug/*' pattern. This allows for automated actions on bug fix branches alongside the main branch, improving development and testing processes.
2024-12-07 17:34:10 +01:00

43 lines
1 KiB
C#

namespace Elsa.Workflows.Runtime;
public class BookmarkQueueSignaler : IBookmarkQueueSignaler
{
private readonly object _lock = new();
private TaskCompletionSource<object?> _tcs = new();
public async Task AwaitAsync(CancellationToken cancellationToken)
{
Task waitTask;
lock (_lock)
{
// Capture the current TCS and await it
waitTask = _tcs.Task;
}
await WaitAndResetAsync(waitTask);
}
public Task TriggerAsync(CancellationToken cancellationToken)
{
lock (_lock)
{
// If TCS is already in a completed state, no need to set it again.
if (!_tcs.Task.IsCompleted)
{
_tcs.SetResult(null);
}
}
return Task.CompletedTask;
}
private async Task WaitAndResetAsync(Task waitTask)
{
await waitTask;
lock (_lock)
{
// Reset the TCS for the next wait
_tcs = new TaskCompletionSource<object?>();
}
}
}