Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/nuget/Delegate.ExpressionEngine…
Browse files Browse the repository at this point in the history
…-4.1.2
  • Loading branch information
pksorensen authored Aug 8, 2024
2 parents 73646b6 + fa4d37e commit 9559743
Show file tree
Hide file tree
Showing 37 changed files with 704 additions and 267 deletions.
31 changes: 20 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,40 @@ jobs:
name: Testing
strategy:
matrix:
dotnet: [ 'net6.0' ]
include:
- framework: "net6.0"
version: 6.0.x
- framework: net8.0
version: 8.0.x

steps:
- name: Checkout code base
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: 8.0.x

- name: Run tests
run: dotnet test --verbosity normal -f ${{ matrix.dotnet }}
run: dotnet test --verbosity normal -f ${{ matrix.framework }}

build:
runs-on: windows-latest
name: Building
strategy:
matrix:
dotnet: ['net6.0']
include:
- framework: "net6.0"
version: 6.0.x
- framework: net8.0
version: 8.0.x
steps:
- name: Checkout code base
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: 8.0.x

- name: Cleaning
run: dotnet clean
Expand All @@ -46,12 +55,12 @@ jobs:
run: dotnet restore WorkflowEngine.sln

- name: Build solution
run: dotnet build -o ../build/${{ matrix.dotnet }} -c Release --no-restore -m:1 -f ${{ matrix.dotnet }}
run: dotnet build -o ../build/${{ matrix.dotnet }} -c Release --no-restore -m:1 -f ${{ matrix.framework }}

- name: Archive build to artifacts
uses: actions/upload-artifact@v2
with:
name: build
path: |
build/${{ matrix.dotnet }}/*
build/${{ matrix.framework }}/*
retention-days: 5
36 changes: 23 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ jobs:
runs-on: windows-latest
name: Testing
strategy:
matrix:
dotnet: [ 'net6.0' ]
matrix:
include:
- framework: "net6.0"
version: 6.0.x
- framework: net8.0
version: 8.0.x
steps:
- name: Checkout code base
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: 8.0.x

- name: Run tests
run: dotnet test --verbosity normal -f ${{ matrix.dotnet }}
run: dotnet test --verbosity normal -f ${{ matrix.framework }}


release:
Expand All @@ -32,16 +36,22 @@ jobs:
- test
steps:
- name: Checkout repo
uses: actions/checkout@v2

- uses: actions/setup-dotnet@v1
uses: actions/checkout@v4

- 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@v4
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 16
node-version: 20

- name: Add plugin for conventional commits
run: npm install conventional-changelog-conventionalcommits
Expand All @@ -62,7 +72,7 @@ jobs:
- name: Print release verison
run: echo ${env:RELEASE_VERSION}

- name: Cleaning
run: dotnet clean

Expand All @@ -80,4 +90,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: thygesteffensen;pksorensen
GIT_AUTHOR_EMAIL: [email protected];[email protected]
run: npx semantic-release
run: npx semantic-release
4 changes: 2 additions & 2 deletions apps/WorkflowEngine.DemoApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IService
(executor) => executor.TriggerAsync(new TriggerContext {
Workflow = workflows.First(),
Trigger = new Trigger { ScheduledTime = DateTimeOffset.UtcNow, Key = workflows.First().Manifest.Triggers.First().Key,
Type =workflows.First().Manifest.Triggers.First().Value.Type }, RunId = Guid.NewGuid() }));
Type =workflows.First().Manifest.Triggers.First().Value.Type }, RunId = Guid.NewGuid() },null));

await c.Response.WriteAsync("Background JOb:" + a);

Expand Down Expand Up @@ -333,7 +333,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IService
Key = workflows.First(w => w.Id.ToString() == c.GetRouteValue("id") as string).Manifest.Triggers.FirstOrDefault().Key
},
Workflow = workflows.First(w=>w.Id.ToString() == c.GetRouteValue("id") as string)
}));
},null));

await c.Response.WriteAsync("Background JOb:" + a);

Expand Down
2 changes: 1 addition & 1 deletion apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire" Version="1.7.31" />
<PackageReference Include="Hangfire" Version="1.8.14" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions src/WorkflowEngine.Core/Action.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using System;
using System;
using System.Collections.Generic;

namespace WorkflowEngine.Core
{
public class Action : IAction, IFormattable
public class Action : Action<IDictionary<string, object>>, IAction
{

}
public class Action<TInput> : IFormattable, IAction<TInput>
{
public DateTimeOffset ScheduledTime { get; set; }

public string Type { get; set; }
public string Key { get; set; }
public Guid RunId { get; set; }
public IDictionary<string, object> Inputs { get; set; }
public TInput Inputs { get; set; }
public int Index { get; set; }
public bool ScopeMoveNext { get; set; }

Expand Down
31 changes: 31 additions & 0 deletions src/WorkflowEngine.Core/ActionCompletedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Newtonsoft.Json;

namespace WorkflowEngine.Core
{
public class ActionCompletedEvent : Event
{
public override EventType EventType => EventType.ActionCompleted;

[JsonProperty("jobId")]
public string JobId { get; set; }
[JsonProperty("actionKey")]
public string ActionKey { get; set; }
[JsonProperty("resultPath")]
public string ResultPath { get; set; }

[JsonProperty("status")]
public string Status { get; set; }

public static ActionCompletedEvent FromAction(IActionResult result,IAction action,string jobId)
{

return new ActionCompletedEvent
{

JobId = jobId,
ActionKey = action.Key,
Status = result.Status,
};
}
}
}
89 changes: 38 additions & 51 deletions src/WorkflowEngine.Core/ActionExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ExpressionEngine;
using ExpressionEngine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
Expand All @@ -15,101 +15,88 @@ public interface IScopeContext
public class ScopeContext : IScopeContext
{
public string Scope { get; set; }
}
public interface IWaitAction
{

}
public class ActionExecutor : IActionExecutor
{
private readonly IOutputsRepository outputsRepository;
private readonly IServiceProvider serviceProvider;
private readonly ILogger logger;
private readonly IScopeContext scopeContext;
private readonly IExpressionEngine expressionEngine;
private readonly IOutputsRepository _outputsRepository;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger _logger;
private readonly IScopeContext _scopeContext;
private readonly IExpressionEngine _expressionEngine;
private Dictionary<string, IActionImplementationMetadata> _implementations;

public ActionExecutor(
IEnumerable<IActionImplementationMetadata> implementations,
IEnumerable<IActionImplementationMetadata> implementations,
IOutputsRepository outputsRepository,
IServiceProvider serviceProvider,
ILogger<ActionExecutor> logger,
IScopeContext scopeContext,
IExpressionEngine expressionEngine)
{
if(implementations.GroupBy(k=>k.Type).Any(c=>c.Count() > 1))

if (implementations.GroupBy(k => k.Type).Any(c => c.Count() > 1))
{
throw new ArgumentException("Double registration of " + String.Join(",", implementations.GroupBy(k => k.Type).Where(c => c.Count() > 1).Select(c=>c.Key)));
throw new ArgumentException("Double registration of " + String.Join(",", implementations.GroupBy(k => k.Type).Where(c => c.Count() > 1).Select(c => c.Key)));
}
_implementations = implementations?.ToDictionary(k => k.Type) ?? throw new ArgumentNullException(nameof(implementations));
this.outputsRepository=outputsRepository??throw new ArgumentNullException(nameof(outputsRepository));
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
this.logger=logger??throw new ArgumentNullException(nameof(logger));
this.scopeContext=scopeContext;
this.expressionEngine=expressionEngine??throw new ArgumentNullException(nameof(expressionEngine));
_outputsRepository = outputsRepository ?? throw new ArgumentNullException(nameof(outputsRepository));
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_scopeContext = scopeContext;
_expressionEngine = expressionEngine ?? throw new ArgumentNullException(nameof(expressionEngine));
}
public async ValueTask<IActionResult> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{

try
{

if (action.ScopeMoveNext)
{
await outputsRepository.EndScope(context, workflow, action);
await _outputsRepository.EndScope(context, workflow, action);
}

var actionMetadata = workflow.Manifest.Actions.FindAction(action.Key);
scopeContext.Scope=action.Key;
action.Inputs = await expressionEngine.ResolveInputs(actionMetadata,logger);

if (actionMetadata == null)
{
//if (workflow.Manifest.Actions.FindParentAction(action.Key) is ForLoopActionMetadata parent)
//{
// await outputsRepository.AddArrayInput(context, workflow, action);
//}
//else
//if (actionMetadata is ForLoopActionMetadata)
//{
// await outputsRepository.StartScope(context, workflow, action);
//}
//else
{
await outputsRepository.AddInput(context, workflow, action);
}
throw new InvalidOperationException($"The action '{action.Key}' was not found. Found keys are: '{string.Join(",",workflow.Manifest.Actions.Keys)}'");
}
_scopeContext.Scope = action.Key;
action.Inputs = await _expressionEngine.ResolveInputs(actionMetadata, _logger);

await _outputsRepository.AddInput(context, workflow, action);

var actionImplementation = serviceProvider.GetRequiredService(_implementations[actionMetadata.Type].Implementation) as IActionImplementation;
var metadata = _implementations[actionMetadata.Type];
var result = await metadata.ExecuteAsync(_serviceProvider, context, workflow, action);


await _outputsRepository.AddAsync(context, workflow, action, result);


return result;

var result = new ActionResult {
Key = action.Key,
Status = "Succeded",
Result = await actionImplementation.ExecuteAsync(context,workflow, action)
};



await outputsRepository.AddAsync(context, workflow, action, result);


return result;


}catch(Exception ex)
}
catch (Exception ex)
{
var result= new ActionResult { Key = action.Key, Status = "Failed", FailedReason=ex.ToString(), ReThrow = (ex is InvalidOperationException) };
var result = new ActionResult { Key = action.Key, Status = "Failed", FailedReason = ex.ToString(), ReThrow = (ex is InvalidOperationException) };
try
{
await outputsRepository.AddAsync(context, workflow, action, result);
await _outputsRepository.AddAsync(context, workflow, action, result);
}
catch (Exception )
catch (Exception exx)

Check warning on line 91 in src/WorkflowEngine.Core/ActionExecutor.cs

View workflow job for this annotation

GitHub Actions / Building (net8.0, 8.0.x)

The variable 'exx' is declared but never used

Check warning on line 91 in src/WorkflowEngine.Core/ActionExecutor.cs

View workflow job for this annotation

GitHub Actions / Building (net8.0, 8.0.x)

The variable 'exx' is declared but never used
{

}
return result;
}
}
}



}
Loading

0 comments on commit 9559743

Please sign in to comment.