Stash
This commit is contained in:
parent
28849695d3
commit
8002f20e50
|
|
@ -24,7 +24,7 @@ using Proto.Persistence.SqlServer;
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ public static class ModuleExtensions
|
|||
|
||||
public static IServiceCollection AddStorageDriver<T>(this IServiceCollection services) where T : class, IStorageDriver
|
||||
{
|
||||
return services.AddSingleton<IStorageDriver, T>();
|
||||
return services
|
||||
.AddSingleton<T>()
|
||||
.AddSingleton<IStorageDriver, T>();
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -118,7 +119,8 @@ public class DefaultBackgroundActivityInvoker : IBackgroundActivityInvoker
|
|||
// - 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();
|
||||
|
|
|
|||
|
|
@ -292,6 +292,19 @@ public class DefaultWorkflowRuntime : IWorkflowRuntime
|
|||
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;
|
||||
|
|
@ -423,11 +436,5 @@ public class DefaultWorkflowRuntime : IWorkflowRuntime
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue