diff --git a/src/WorkflowCore/Interface/ISyncWorkflowRunner.cs b/src/WorkflowCore/Interface/ISyncWorkflowRunner.cs index 051b59e91..7fa9c0688 100644 --- a/src/WorkflowCore/Interface/ISyncWorkflowRunner.cs +++ b/src/WorkflowCore/Interface/ISyncWorkflowRunner.cs @@ -7,10 +7,14 @@ namespace WorkflowCore.Interface { public interface ISyncWorkflowRunner { - Task RunWorkflowSync(string workflowId, int version, TData data, string reference, TimeSpan timeOut, bool persistSate = true) + Task RunWorkflowSync(string workflowId, int version, TData data, string reference, TimeSpan timeOut, bool persistState = true) where TData : new(); - Task RunWorkflowSync(string workflowId, int version, TData data, string reference, CancellationToken token, bool persistSate = true) + Task RunWorkflowSync(string workflowId, int version, TData data, string reference, CancellationToken token, bool persistState = true) where TData : new(); + + Task ResumeWorkflowSync(string workflowId, TimeSpan timeOut, bool persistState = true); + + Task ResumeWorkflowSync(string workflowId, CancellationToken token, bool persistState = true); } } \ No newline at end of file diff --git a/src/WorkflowCore/Services/SyncWorkflowRunner.cs b/src/WorkflowCore/Services/SyncWorkflowRunner.cs index 5317a8966..819a7c835 100644 --- a/src/WorkflowCore/Services/SyncWorkflowRunner.cs +++ b/src/WorkflowCore/Services/SyncWorkflowRunner.cs @@ -31,14 +31,14 @@ public SyncWorkflowRunner(IWorkflowHost host, IWorkflowExecutor executor, IDistr } public Task RunWorkflowSync(string workflowId, int version, TData data, - string reference, TimeSpan timeOut, bool persistSate = true) + string reference, TimeSpan timeOut, bool persistState = true) where TData : new() { return RunWorkflowSync(workflowId, version, data, reference, new CancellationTokenSource(timeOut).Token, - persistSate); + persistState); } - public async Task RunWorkflowSync(string workflowId, int version, TData data, string reference, CancellationToken token, bool persistSate = true) + public async Task RunWorkflowSync(string workflowId, int version, TData data, string reference, CancellationToken token, bool persistState = true) where TData : new() { var def = _registry.GetDefinition(workflowId, version); @@ -71,14 +71,31 @@ public async Task RunWorkflowSync(string workflowId, in var id = Guid.NewGuid().ToString(); - if (persistSate) + if (persistState) id = await _persistenceStore.CreateNewWorkflow(wf, token); else wf.Id = id; + return await RunWorkflowInstanceSync(wf, token, persistState); + } + + public Task ResumeWorkflowSync(string workflowId, TimeSpan timeOut, bool persistState = true) + { + return ResumeWorkflowSync(workflowId, new CancellationTokenSource(timeOut).Token, persistState); + } + + public async Task ResumeWorkflowSync(string workflowId, CancellationToken token, bool persistState = true) + { + WorkflowInstance wf = await _persistenceStore.GetWorkflowInstance(workflowId); + + return await RunWorkflowInstanceSync(wf, token, persistState); + } + + private async Task RunWorkflowInstanceSync(WorkflowInstance wf, CancellationToken token, bool persistState) + { wf.Status = WorkflowStatus.Runnable; - - if (!await _lockService.AcquireLock(id, CancellationToken.None)) + + if (!await _lockService.AcquireLock(wf.Id, CancellationToken.None)) { throw new InvalidOperationException(); } @@ -88,17 +105,17 @@ public async Task RunWorkflowSync(string workflowId, in while ((wf.Status == WorkflowStatus.Runnable) && !token.IsCancellationRequested) { await _executor.Execute(wf, token); - if (persistSate) + if (persistState) await _persistenceStore.PersistWorkflow(wf, token); } } finally { - await _lockService.ReleaseLock(id); + await _lockService.ReleaseLock(wf.Id); } - if (persistSate) - await _queueService.QueueWork(id, QueueType.Index); + if (persistState) + await _queueService.QueueWork(wf.Id, QueueType.Index); return wf; }