Skip to content

Commit

Permalink
Merge pull request #11 from delegateas/pks/fixjobnames
Browse files Browse the repository at this point in the history
Pks/fixjobnames
  • Loading branch information
pksorensen authored Feb 17, 2022
2 parents a37d7ad + 04cd914 commit 9ad3069
Show file tree
Hide file tree
Showing 35 changed files with 1,061 additions and 121 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ jobs:
steps:
- name: Checkout code base
uses: actions/checkout@v2


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

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

Expand All @@ -33,7 +37,7 @@ jobs:

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

- name: Cleaning
run: dotnet clean
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v2


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

- name: Setup Node.js
uses: actions/setup-node@v1
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
- name: Checkout code base
uses: actions/checkout@v2

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

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

Expand All @@ -29,6 +33,10 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v2

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

- name: Setup Node.js
uses: actions/setup-node@v1
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,6 @@ Service Registration
}
}
});
```
```

### TODO Show Loop example
201 changes: 191 additions & 10 deletions apps/WorkflowEngine.DemoApp/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
using ExpressionEngine;
using Hangfire;
using Hangfire.SqlServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Abstractions;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using WorkflowEngine.Core;
using WorkflowEngine.Core.Actions;
using WorkflowEngine.Core.Expressions;

namespace WorkflowEngine.DemoApp
{
Expand All @@ -23,7 +29,7 @@ public class SendEmailAction : IActionImplementation
public const string SendEmailActionType = "SendEmailAction";


public async ValueTask<object> ExecuteAsync(IWorkflow workflow, IAction action)
public async ValueTask<object> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{
await Task.Delay(TimeSpan.FromMinutes(3));

Expand All @@ -36,7 +42,7 @@ public class EAVCreateAction : IActionImplementation
public const string EAVCreateActionType = "EAVCreateAction";


public async ValueTask<object> ExecuteAsync(IWorkflow workflow, IAction action)
public async ValueTask<object> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{
Console.WriteLine($"Hello world from 1");
await Task.Delay(TimeSpan.FromMinutes(3));
Expand All @@ -46,9 +52,60 @@ public async ValueTask<object> ExecuteAsync(IWorkflow workflow, IAction action)
return null;
}
}

public class RetrieveRecordAction : IActionImplementation
{
private readonly IExpressionEngine expressionEngine;

public RetrieveRecordAction(IExpressionEngine expressionEngine)
{
this.expressionEngine=expressionEngine;
}
public ValueTask<object> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{
// var next = workflow.Manifest.Actions.FindAction(action.Key);
var inputs = action.Inputs;



return new ValueTask<object>(new
{
id = Guid.Parse(inputs["recordId"]?.ToString()),
targetgroupid = Guid.NewGuid()
});
}
}
public class RetrieveTargetGroupTargetsAction : IActionImplementation
{
public ValueTask<object> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{
return new ValueTask<object>(new
{
value = new[] { new { targetid=Guid.NewGuid()}, new { targetid = Guid.NewGuid() } }
});
}
}
public class FindFormSubmissionForAccountAction : IActionImplementation
{
public ValueTask<object> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{
var next = workflow.Manifest.Actions.FindAction(action.Key);

return new ValueTask<object>(new { formsubmissionid = Guid.NewGuid() });
}
}
public class CreateESDHCaseFromFormSubmissionAction : IActionImplementation
{
public ValueTask<object> ExecuteAsync(IRunContext context, IWorkflow workflow, IAction action)
{
var next = workflow.Manifest.Actions.FindAction(action.Key);

return new ValueTask<object>(new { id = Guid.NewGuid() });
}
}



public class Startup
{

Expand All @@ -73,6 +130,8 @@ public void ConfigureServices(IServiceCollection services)

services.AddHangfireServer();
services.AddRazorPages();
services.AddExpressionEngine();


services.AddTransient<IWorkflowExecutor, WorkflowExecutor>();
services.AddTransient<IActionExecutor, ActionExecutor>();
Expand All @@ -81,7 +140,16 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<IWorkflowRepository, DefaultWorkflowRepository>();
services.AddAction<SendEmailAction>(SendEmailAction.SendEmailActionType);
services.AddAction<EAVCreateAction>(EAVCreateAction.EAVCreateActionType);

services.AddAction<RetrieveRecordAction>();
services.AddAction<RetrieveTargetGroupTargetsAction>();
services.AddAction<FindFormSubmissionForAccountAction>();
services.AddAction<CreateESDHCaseFromFormSubmissionAction>();
services.AddAction<ForeachAction>("Foreach");
services.AddSingleton<IOutputsRepository, DefaultOutputsRepository>();
services.AddFunctions();
services.AddScoped<IRunContextAccessor, RunContextFactory>();
services.AddScoped<IArrayContext, ArrayContext>();
services.AddScoped<IScopeContext, ScopeContext>();
services.AddSingleton<IWorkflow>(new Workflow
{
Id = Guid.Empty,
Expand All @@ -93,11 +161,11 @@ public void ConfigureServices(IServiceCollection services)
["Trigger"] = new TriggerMetadata
{
Type = "EAVTrigger",
Inputs =
{
["operation"] = "create",
["entity"] ="targetgroupresults"
}
//Inputs =
//{
// ["operation"] = "create",
// ["entity"] ="targetgroupresults"
//}
}
},
Actions =
Expand All @@ -123,7 +191,87 @@ public void ConfigureServices(IServiceCollection services)
}
});

// services.AddScoped()
services.AddSingleton<IWorkflow>(new Workflow
{
Id = Guid.Parse("dd087e82-c61a-4ce2-b961-b976baa4bf17"),
Version = "1.0",
Manifest = new WorkflowManifest
{
Triggers =
{
["Trigger"] = new TriggerMetadata
{
Type = "Manual",

}
},
Actions =
{
[nameof(RetrieveRecordAction)] = new ActionMetadata
{
Type = nameof(RetrieveRecordAction),
Inputs =
{
["entityName"] = "forms",
["recordId"] = "@triggerBody()?['recordId']"
}
},
[nameof(RetrieveTargetGroupTargetsAction)] = new ActionMetadata
{
Type = nameof(RetrieveTargetGroupTargetsAction),
RunAfter = new WorkflowRunAfterActions
{
[nameof(RetrieveRecordAction)] = new []{"Succeded"}
},
Inputs =
{
["targetgroupid"] = $"@outputs('{nameof(RetrieveRecordAction)}')?['body/targetgroupid']"
}
},
["Loop_over_targetgroup"] = new ForLoopActionMetadata
{
RunAfter = new WorkflowRunAfterActions
{
[nameof(RetrieveTargetGroupTargetsAction)] = new []{"Succeded"}
},
ForEach = $"@outputs('{nameof(RetrieveTargetGroupTargetsAction)}')?['body/value']",
Type = "Foreach",
Inputs =
{

},
Actions =
{
[nameof(FindFormSubmissionForAccountAction)] = new ActionMetadata
{
Type = nameof(FindFormSubmissionForAccountAction),
Inputs =
{
["accountid"] = "@items('Loop_over_targetgroup')?['targetid']",
["formid"] = "@triggerBody()?['recordId']",
}
},
[nameof(CreateESDHCaseFromFormSubmissionAction)] = new ActionMetadata
{
RunAfter = new WorkflowRunAfterActions
{
[nameof(FindFormSubmissionForAccountAction)] = new []{"Succeded"}
},
Type = nameof(CreateESDHCaseFromFormSubmissionAction),
Inputs =
{
["formsubmissionid"] = $"@outputs('{nameof(FindFormSubmissionForAccountAction)}')?['body/formsubmissionid']",
}
}

}
}

}
}
});

// services.AddScoped()
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -148,7 +296,40 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IService
var workflows = await c.RequestServices.GetRequiredService<IWorkflowRepository>().GetAllWorkflows();

var a = Hangfire.BackgroundJob.Enqueue<IHangfireWorkflowExecutor>(
(executor) => executor.TriggerAsync(new TriggerContext { Workflow = workflows.First() }));
(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() }));

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

// c.RequestServices.GetRequiredService


});

endpoints.MapGet("/runs", async c =>
{
await c.Response.WriteAsync(JToken.FromObject(c.RequestServices.GetRequiredService<IOutputsRepository>()).ToString());
});
endpoints.MapGet("/magic/{id}", async c =>
{
var workflows = await c.RequestServices.GetRequiredService<IWorkflowRepository>().GetAllWorkflows();
var inputs = new Dictionary<string, object>
{
["recordId"] = Guid.NewGuid(),
["entityName"] ="Forms",
};
var a = Hangfire.BackgroundJob.Enqueue<IHangfireWorkflowExecutor>(
(executor) => executor.TriggerAsync(new TriggerContext {
RunId = Guid.NewGuid() ,
Trigger = new Trigger {
Inputs = inputs,
ScheduledTime = DateTimeOffset.UtcNow, Type=workflows.First(w => w.Id.ToString() == c.GetRouteValue("id") as string).Manifest.Triggers.FirstOrDefault().Value.Type,
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)
}));

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

Expand Down
6 changes: 3 additions & 3 deletions apps/WorkflowEngine.DemoApp/WorkflowEngine.DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hangfire" Version="1.7.24"/>
<PackageReference Include="Hangfire" Version="1.7.28" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\WorkflowEngine.Core\WorkflowEngine.Core.csproj"/>
<ProjectReference Include="..\..\src\WorkflowEngine.Hangfire\WorkflowEngine.Hangfire.csproj"/>
<ProjectReference Include="..\..\src\WorkflowEngine.Core\WorkflowEngine.Core.csproj" />
<ProjectReference Include="..\..\src\WorkflowEngine.Hangfire\WorkflowEngine.Hangfire.csproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/WorkflowEngine.Core/Action.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace WorkflowEngine.Core
{
Expand All @@ -8,6 +9,10 @@ public class Action : IAction, IFormattable

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

public string ToString(string format, IFormatProvider formatProvider)
{
Expand Down
Loading

0 comments on commit 9ad3069

Please sign in to comment.