Skip to content

Commit

Permalink
Stash
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmskywalker committed Jan 3, 2024
1 parent 2884969 commit 8002f20
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/bundles/Elsa.Server.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
const bool useMongoDb = false;
const bool useSqlServer = false;
const bool useDapper = false;
const bool useProtoActor = true;
const bool useProtoActor = false;
const bool useHangfire = false;
const bool useQuartz = true;
const bool useMassTransit = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static IModule UseWorkflows(this IModule configuration, Action<WorkflowsF

public static IServiceCollection AddStorageDriver<T>(this IServiceCollection services) where T : class, IStorageDriver
{
return services.AddSingleton<IStorageDriver, T>();
return services
.AddSingleton<T>()
.AddSingleton<IStorageDriver, T>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ public interface IWorkflowRuntime
/// Counts the number of workflow instances based on the provided query args.
/// </summary>
Task<long> CountRunningWorkflowsAsync(CountRunningWorkflowsRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Merges the specified workflow state into the workflow runtime.
/// </summary>
Task MergeWorkflowStateAsync(WorkflowState workflowState, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class DefaultBackgroundActivityInvoker : IBackgroundActivityInvoker
public async Task ExecuteAsync(ScheduledBackgroundActivity scheduledBackgroundActivity, CancellationToken cancellationToken = default)
{
var workflowInstanceId = scheduledBackgroundActivity.WorkflowInstanceId;

var workflowState = await _workflowRuntime.ExportWorkflowStateAsync(workflowInstanceId, cancellationToken);

if (workflowState == null)
Expand Down Expand Up @@ -118,7 +119,8 @@ public async Task ExecuteAsync(ScheduledBackgroundActivity scheduledBackgroundAc
// - Bookmarks
workflowState = _workflowStateExtractor.Extract(workflowExecutionContext);
await _variablePersistenceManager.SaveVariablesAsync(workflowExecutionContext);
await _workflowRuntime.ImportWorkflowStateAsync(workflowState, cancellationToken);
await _workflowRuntime.MergeWorkflowStateAsync(workflowState, cancellationToken);
//await _workflowRuntime.ImportWorkflowStateAsync(workflowState, cancellationToken);

// Process bookmarks.
var newBookmarks = workflowExecutionContext.Bookmarks.ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ public async Task<long> CountRunningWorkflowsAsync(CountRunningWorkflowsRequest
return await _workflowInstanceStore.CountAsync(filter, cancellationToken);
}

public async Task MergeWorkflowStateAsync(WorkflowState workflowState, CancellationToken cancellationToken = default)
{
var existingWorkflowInstance = (await _workflowInstanceStore.FindAsync(workflowState.Id, cancellationToken))!;
var workflowInstance = _workflowStateMapper.Map(workflowState)!;

foreach (var bookmark in workflowState.Bookmarks)
{
existingWorkflowInstance.WorkflowState.Bookmarks.RemoveWhere(x => x.Id == bookmark.Id);
existingWorkflowInstance.WorkflowState.Bookmarks.Add(bookmark);
}
await _workflowInstanceManager.SaveAsync(workflowInstance, cancellationToken);
}

private async Task<WorkflowExecutionResult> StartWorkflowAsync(IWorkflowHost workflowHost, StartWorkflowRuntimeOptions options)
{
var workflowInstanceId = string.IsNullOrEmpty(options.InstanceId) ? _identityGenerator.GenerateId() : options.InstanceId;
Expand Down Expand Up @@ -423,11 +436,5 @@ private async Task<IEnumerable<WorkflowMatch>> FindResumableWorkflowsAsync(Workf
private async Task<IDistributedSynchronizationHandle> AcquireLockAsync(string resource, CancellationToken cancellationToken)
{
return await _distributedLockProvider.AcquireLockAsync(resource, TimeSpan.FromMinutes(2), cancellationToken);
// if (AcquiredLock.Value?.Key == resource)
// return AcquiredLock.Value.Lock;
//
// var distributedLock = await _distributedLockProvider.AcquireLockAsync(resource, TimeSpan.FromMinutes(2), cancellationToken);
// AcquiredLock.Value = new AcquiredLock { Lock = distributedLock, Key = resource };
// return distributedLock;
}
}

0 comments on commit 8002f20

Please sign in to comment.