From 8420bd6acfd577a2670b51bb7cc5c28b5dff5b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Tue, 6 Dec 2022 12:39:17 +0100 Subject: [PATCH 1/9] removed not used interface elements --- src/WorkflowEngine.Core/IOutputsRepository.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/WorkflowEngine.Core/IOutputsRepository.cs b/src/WorkflowEngine.Core/IOutputsRepository.cs index 4afcd1f..4d8aeb4 100644 --- a/src/WorkflowEngine.Core/IOutputsRepository.cs +++ b/src/WorkflowEngine.Core/IOutputsRepository.cs @@ -10,10 +10,6 @@ public interface IOutputsRepository ValueTask GetTriggerData(Guid id); ValueTask AddInput(IRunContext context, IWorkflow workflow, IAction action); ValueTask GetOutputData(Guid id, string v); - ValueTask AddArrayItemAsync(IRunContext run, IWorkflow workflow, string key, IActionResult result); - ValueTask AddArrayInput(IRunContext context, IWorkflow workflow, IAction action); - ValueTask StartScope(IRunContext context, IWorkflow workflow, IAction action); - ValueTask AddScopeItem(IRunContext context, IWorkflow workflow, IAction action, IActionResult result); ValueTask EndScope(IRunContext run, IWorkflow workflow, IAction action); } From 2a31c7bccfaa2bd261536903afce5099ea0a1fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Tue, 6 Dec 2022 12:52:30 +0100 Subject: [PATCH 2/9] fix: updated deps --- apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj | 4 ++-- src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj b/apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj index 6db342b..c1650e9 100644 --- a/apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj +++ b/apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,7 +7,7 @@ - + diff --git a/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj b/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj index 49c3498..239f5ad 100644 --- a/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj +++ b/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1;net6.0 @@ -11,7 +11,7 @@ - + From 79c6e61b0f4db4744417ee54cd0c8ce00ea42e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Sat, 14 Jan 2023 07:15:54 +0100 Subject: [PATCH 3/9] fix: use scopedactionmetadata to control if a scope should be used to find next action --- src/WorkflowEngine.Core/WorkflowActions.cs | 1 + src/WorkflowEngine.Core/WorkflowExecutor.cs | 7 ++----- .../HangfireWorkflowExecutor.cs | 17 ++++++----------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/WorkflowEngine.Core/WorkflowActions.cs b/src/WorkflowEngine.Core/WorkflowActions.cs index 7a551b4..56a1e60 100644 --- a/src/WorkflowEngine.Core/WorkflowActions.cs +++ b/src/WorkflowEngine.Core/WorkflowActions.cs @@ -14,6 +14,7 @@ public class ForLoopActionMetadata : ActionMetadata, IScopedActionMetadata public interface IScopedActionMetadata { WorkflowActions Actions { get; set; } + string Type { get; set; } } public class WorkflowActions : Dictionary { diff --git a/src/WorkflowEngine.Core/WorkflowExecutor.cs b/src/WorkflowEngine.Core/WorkflowExecutor.cs index 04e957a..80527ee 100644 --- a/src/WorkflowEngine.Core/WorkflowExecutor.cs +++ b/src/WorkflowEngine.Core/WorkflowExecutor.cs @@ -28,12 +28,9 @@ public WorkflowExecutor(ILogger logger, IOutputsRepository ou public ValueTask GetNextAction(IRunContext context, IWorkflow workflow, IActionResult priorResult) { logger.LogInformation("Finding Next Action for {WorkflowId} and prior {@result} ", workflow.Id, priorResult); - //var action = workflow.Manifest.Actions.Single(c => c.Key == priorResult.Key); - - + var next = workflow.Manifest.Actions.FindNextAction(priorResult.Key); - //var parent = workflow.Manifest.Actions.FindParentAction(priorResult.Key) is ForLoopActionMetadata; - + if (next.IsDefault()) return new ValueTask(); diff --git a/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs b/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs index f7c7101..5e49760 100644 --- a/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs +++ b/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs @@ -98,17 +98,12 @@ public async ValueTask ExecuteAsync(IRunContext run, IWorkflow workflow, { var result = await actionExecutor.ExecuteAsync(run, workflow, action); - - - - + if (result != null) - { - + { var next = await executor.GetNextAction(run, workflow, result); - - + await hangfireActionExecutorResultHandler.InspectAsync(run, workflow, result, next); if (next != null) @@ -116,13 +111,13 @@ public async ValueTask ExecuteAsync(IRunContext run, IWorkflow workflow, var a = backgroundJobClient.Enqueue( (executor) => executor.ExecuteAsync(run, workflow, next, null)); } - else if (workflow.Manifest.Actions.FindParentAction(action.Key) is ForLoopActionMetadata scope) + else if (workflow.Manifest.Actions.FindParentAction(action.Key) is IScopedActionMetadata scope) { var scopeaction = run.CopyTo(new Action { ScopeMoveNext = true, Type = scope.Type, Key = action.Key.Substring(0, action.Key.LastIndexOf('.')), ScheduledTime = DateTimeOffset.UtcNow }); - - var a = backgroundJobClient.Enqueue( + + var a = backgroundJobClient.ContinueJobWith(context.BackgroundJob.Id, (executor) => executor.ExecuteAsync(run, workflow, scopeaction, null)); //await outputRepository.EndScope(run, workflow, action); From 147fb3a2812ccac3e696dc62a0ff07eed9ab2f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Sat, 14 Jan 2023 07:50:33 +0100 Subject: [PATCH 4/9] fix: used node 18 for build --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 84d969f..d8f0426 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,7 +41,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v1 with: - node-version: 16 + node-version: 18 - name: Add plugin for conventional commits run: npm install conventional-changelog-conventionalcommits From 13e2bd4c34bd5862b1dd71559d2a1f2f3fdccefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Sat, 14 Jan 2023 13:03:16 +0100 Subject: [PATCH 5/9] fix: added git forwindows in pipelines --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8f0426..d2a0a2b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,10 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v2 - + + - name: Setup Git for Windows' minimal SDK + uses: git-for-windows/setup-git-for-windows-sdk@v1 + - uses: actions/setup-dotnet@v1 with: dotnet-version: '6.0.x' From 7be4e888f84587666d6c2842ea3e263a6699fafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Sat, 14 Jan 2023 13:43:40 +0100 Subject: [PATCH 6/9] test path --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d2a0a2b..c940a5d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,9 @@ jobs: - name: Setup Git for Windows' minimal SDK uses: git-for-windows/setup-git-for-windows-sdk@v1 + - name: Print GIT verison + run: git --version + - uses: actions/setup-dotnet@v1 with: dotnet-version: '6.0.x' @@ -65,7 +68,7 @@ jobs: - name: Print release verison run: echo ${env:RELEASE_VERSION} - + - name: Cleaning run: dotnet clean From c295d6e190041bb7463758333c9972d9c29f9ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Sat, 14 Jan 2023 14:00:25 +0100 Subject: [PATCH 7/9] old version? --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c940a5d..7c304d6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,7 +64,7 @@ jobs: GIT_AUTHOR_NAME: thygesteffensen;pksorensen GIT_AUTHOR_EMAIL: 31892312+thygesteffensen@users.noreply.github.com run: | - echo "RELEASE_VERSION=$((npx semantic-release --dry-run).Where({ $_ -like '*Release note*' }) | Out-String | Select-String '[0-9]+\.[0-9]+\.[0-9]+([-][a-zA-z]+[.][0-9]*)?' | % { $_.Matches } | % { $_.Value })" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "RELEASE_VERSION=$((npx semantic-release@19.0.5 --dry-run).Where({ $_ -like '*Release note*' }) | Out-String | Select-String '[0-9]+\.[0-9]+\.[0-9]+([-][a-zA-z]+[.][0-9]*)?' | % { $_.Matches } | % { $_.Value })" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - name: Print release verison run: echo ${env:RELEASE_VERSION} From 3443315e48dead1aaba57af293c9bbf110d48218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Sat, 14 Jan 2023 14:09:10 +0100 Subject: [PATCH 8/9] fix: using old version --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c304d6..63dd516 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -86,4 +86,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GIT_AUTHOR_NAME: thygesteffensen;pksorensen GIT_AUTHOR_EMAIL: 31892312+thygesteffensen@users.noreply.github.com;poul@kjeldager.com - run: npx semantic-release \ No newline at end of file + run: npx semantic-release@19.0.5 \ No newline at end of file From 6e1bbc5c6b2e709a48bda5104f6d361306a1727c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Poul=20Kjeldager=20S=C3=B8rensen?= Date: Thu, 2 Nov 2023 13:06:06 +0100 Subject: [PATCH 9/9] fix: added multiple trigger support for timed triggers --- .../ExpressionEngineExtensions.cs | 2 +- .../DependencyInjectionExtensions.cs | 2 +- .../WorkflowEngine.Hangfire.csproj | 9 ++-- .../WorkflowStarterBackgroundJob.cs | 50 +++++++++++-------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/WorkflowEngine.Core/ExpressionEngineExtensions.cs b/src/WorkflowEngine.Core/ExpressionEngineExtensions.cs index 5410c4c..8a62f0d 100644 --- a/src/WorkflowEngine.Core/ExpressionEngineExtensions.cs +++ b/src/WorkflowEngine.Core/ExpressionEngineExtensions.cs @@ -28,7 +28,7 @@ public static async ValueTask> ResolveInputs(this IEx { var resolvedInputs = new Dictionary(); - + if(actionMetadata.Inputs!=null) foreach (var input in actionMetadata.Inputs) { if (input.Value is string str && str.Contains("@")) diff --git a/src/WorkflowEngine.Hangfire/DependencyInjectionExtensions.cs b/src/WorkflowEngine.Hangfire/DependencyInjectionExtensions.cs index c941db5..15d5cb2 100644 --- a/src/WorkflowEngine.Hangfire/DependencyInjectionExtensions.cs +++ b/src/WorkflowEngine.Hangfire/DependencyInjectionExtensions.cs @@ -25,7 +25,7 @@ public static IServiceCollection AddWorkflowEngine(this ISer services.AddFunctions(); services.AddScoped(); - services.AddSingleton(); + services.AddTransient(); services.AddHostedService(); diff --git a/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj b/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj index 239f5ad..1e1d50b 100644 --- a/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj +++ b/src/WorkflowEngine.Hangfire/WorkflowEngine.Hangfire.csproj @@ -21,11 +21,8 @@ - - - - - - + + + diff --git a/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs b/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs index 4002660..c134042 100644 --- a/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs +++ b/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs @@ -32,28 +32,31 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) foreach (var workflow in await workflows.GetAllWorkflows()) { - var trigger = workflow.Manifest.Triggers.FirstOrDefault(t => t.Value.Type == "TimerTrigger"); - if (!trigger.Equals(default(KeyValuePair))) + foreach (var trigger in workflow.Manifest.Triggers.Where(t => t.Value.Type == "TimerTrigger")) { - - workflow.Manifest = null; - - jobs.AddOrUpdate(workflow.Id.ToString(), - (executor) => executor.TriggerAsync(new TriggerContext - { - Workflow = workflow, - Trigger = new Trigger + + if (!trigger.Equals(default(KeyValuePair))) + { + + workflow.Manifest = null; + + jobs.AddOrUpdate(workflow.Id.ToString() + trigger.Key, + (System.Linq.Expressions.Expression>)((executor) => executor.TriggerAsync(new TriggerContext { - Inputs = trigger.Value.Inputs, - ScheduledTime = DateTimeOffset.UtcNow, - Type = trigger.Value.Type, - Key = trigger.Key - }, - }), trigger.Value.Inputs["cronExpression"] as string); - - if (first && trigger.Value.Inputs.ContainsKey("runAtStartup") && (bool)trigger.Value.Inputs["runAtStartup"]) - jobs.Trigger(workflow.Id.ToString()); + Workflow = workflow, + Trigger = new Trigger + { + Inputs = trigger.Value.Inputs, + ScheduledTime = DateTimeOffset.UtcNow, + Type = trigger.Value.Type, + Key = trigger.Key + }, + })), trigger.Value.Inputs["cronExpression"] as string, GetTimeZone(trigger)); + + if (first && trigger.Value.Inputs.ContainsKey("runAtStartup") && (bool)trigger.Value.Inputs["runAtStartup"]) + jobs.Trigger(workflow.Id.ToString()); + } } } @@ -66,7 +69,14 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) } - + static TimeZoneInfo GetTimeZone(KeyValuePair trigger) + { + + if (trigger.Value.Inputs.ContainsKey("timezone") && trigger.Value.Inputs["timezone"] is string zone && !string.IsNullOrWhiteSpace(zone)) + return TimeZoneInfo.FindSystemTimeZoneById(zone) ?? TimeZoneInfo.Utc; + return TimeZoneInfo.Utc; + + } } } }