Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distributed locking to MassTransitWorkflowDispatcher #5418

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Elsa.Workflows.Runtime.Requests;
using Elsa.Workflows.Runtime.Responses;
using MassTransit;
using Medallion.Threading;
using Microsoft.Extensions.Logging;

namespace Elsa.MassTransit.Services;
Expand All @@ -26,6 +27,7 @@ public class MassTransitWorkflowDispatcher(
IBookmarkHasher bookmarkHasher,
ITriggerStore triggerStore,
IBookmarkStore bookmarkStore,
IDistributedLockProvider distributedLockProvider,
ILogger<MassTransitWorkflowDispatcher> logger)
: IWorkflowDispatcher
{
Expand Down Expand Up @@ -163,6 +165,8 @@ private async Task DispatchBookmarksAsync(IEnumerable<StoredBookmark> bookmarks,

if (input != null || properties != null)
{
// Need to acquire a lock on the workflow instance to prevent concurrent updates.
await using var distributedLock = await distributedLockProvider.AcquireLockAsync(workflowInstanceId, TimeSpan.FromMinutes(2), cancellationToken);
var workflowInstance = await workflowInstanceManager.FindByIdAsync(workflowInstanceId, cancellationToken);

if (workflowInstance == null)
Expand Down
Loading