-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from danielgerlag/read-ahead
- Loading branch information
Showing
91 changed files
with
1,628 additions
and
840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Workflow Core 1.3.0 | ||
|
||
* Added support for async steps | ||
|
||
Simply inherit from `StepBodyAsync` instead of `StepBody` | ||
|
||
```c# | ||
public class DoSomething : StepBodyAsync | ||
{ | ||
public override async Task<ExecutionResult> RunAsync(IStepExecutionContext context) | ||
{ | ||
await Task.Delay(2000); | ||
return ExecutionResult.Next(); | ||
} | ||
} | ||
``` | ||
|
||
* Migrated from managing own thread pool to TPL datablocks for queue consumers | ||
|
||
* After executing a workflow, will determine if it is scheduled to run before the next poll, if so, will delay queue it |
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...rkflowCore/Interface/IBackgroundWorker.cs → ...WorkflowCore/Interface/IBackgroundTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace WorkflowCore.Interface | ||
{ | ||
public interface IDateTimeProvider | ||
{ | ||
DateTime Now { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using WorkflowCore.Interface; | ||
|
||
namespace WorkflowCore.Models | ||
{ | ||
public abstract class StepBodyAsync : IStepBody | ||
{ | ||
public abstract Task<ExecutionResult> RunAsync(IStepExecutionContext context); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/WorkflowCore/Services/BackgroundTasks/EventConsumer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using WorkflowCore.Interface; | ||
using WorkflowCore.Models; | ||
|
||
namespace WorkflowCore.Services.BackgroundTasks | ||
{ | ||
internal class EventConsumer : QueueConsumer, IBackgroundTask | ||
{ | ||
private readonly IPersistenceProvider _persistenceStore; | ||
private readonly IDistributedLockProvider _lockProvider; | ||
private readonly IDateTimeProvider _datetimeProvider; | ||
|
||
protected override QueueType Queue => QueueType.Event; | ||
|
||
public EventConsumer(IPersistenceProvider persistenceStore, IQueueProvider queueProvider, ILoggerFactory loggerFactory, IServiceProvider serviceProvider, IWorkflowRegistry registry, IDistributedLockProvider lockProvider, WorkflowOptions options, IDateTimeProvider datetimeProvider) | ||
: base(queueProvider, loggerFactory, options) | ||
{ | ||
_persistenceStore = persistenceStore; | ||
_lockProvider = lockProvider; | ||
_datetimeProvider = datetimeProvider; | ||
} | ||
|
||
protected override async Task ProcessItem(string itemId, CancellationToken cancellationToken) | ||
{ | ||
if (await _lockProvider.AcquireLock($"evt:{itemId}", cancellationToken)) | ||
{ | ||
try | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
var evt = await _persistenceStore.GetEvent(itemId); | ||
if (evt.EventTime <= _datetimeProvider.Now.ToUniversalTime()) | ||
{ | ||
var subs = await _persistenceStore.GetSubcriptions(evt.EventName, evt.EventKey, evt.EventTime); | ||
var success = true; | ||
|
||
foreach (var sub in subs.ToList()) | ||
success = success && await SeedSubscription(evt, sub, cancellationToken); | ||
|
||
if (success) | ||
await _persistenceStore.MarkEventProcessed(itemId); | ||
} | ||
} | ||
finally | ||
{ | ||
await _lockProvider.ReleaseLock($"evt:{itemId}"); | ||
} | ||
} | ||
else | ||
{ | ||
Logger.LogInformation($"Event locked {itemId}"); | ||
} | ||
} | ||
|
||
private async Task<bool> SeedSubscription(Event evt, EventSubscription sub, CancellationToken cancellationToken) | ||
{ | ||
if (await _lockProvider.AcquireLock(sub.WorkflowId, cancellationToken)) | ||
{ | ||
try | ||
{ | ||
var workflow = await _persistenceStore.GetWorkflowInstance(sub.WorkflowId); | ||
var pointers = workflow.ExecutionPointers.Where(p => p.EventName == sub.EventName && p.EventKey == sub.EventKey && !p.EventPublished); | ||
foreach (var p in pointers) | ||
{ | ||
p.EventData = evt.EventData; | ||
p.EventPublished = true; | ||
p.Active = true; | ||
} | ||
workflow.NextExecution = 0; | ||
await _persistenceStore.PersistWorkflow(workflow); | ||
await _persistenceStore.TerminateSubscription(sub.Id); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogError(ex.Message); | ||
return false; | ||
} | ||
finally | ||
{ | ||
await _lockProvider.ReleaseLock(sub.WorkflowId); | ||
await QueueProvider.QueueWork(sub.WorkflowId, QueueType.Workflow); | ||
} | ||
} | ||
else | ||
{ | ||
Logger.LogInformation("Workflow locked {0}", sub.WorkflowId); | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.