diff --git a/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs b/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs index 81866bd..4c6772d 100644 --- a/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs +++ b/src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs @@ -1,4 +1,4 @@ -using Hangfire; +using Hangfire; using Hangfire.Server; using System; using System.Collections.Generic; @@ -36,7 +36,7 @@ public static string TriggerAsync(this IBackgroundJobClient bac where TTriggerContext : TriggerContext { var job = backgroundJobClient.Enqueue( - (executor) => executor.TriggerAsync(trigger)); + (executor) => executor.TriggerAsync(trigger,null)); return job; @@ -95,13 +95,7 @@ public async ValueTask ExecuteAsync(IRunContext run, IWorkflow workflow, { var result = await actionExecutor.ExecuteAsync(run, workflow, action); - await outputRepository.AddEvent(run, workflow, action, new ActionCompletedEvent - { - // TODO: Add path to action in state - // assignees: thygesteffensen - JobId = context.BackgroundJob.Id, - ActionKey = action.Key - }); + await outputRepository.AddEvent(run, workflow, action, ActionCompletedEvent.FromAction(result,action,context.BackgroundJob.Id)); if (result != null) { @@ -127,12 +121,12 @@ public async ValueTask ExecuteAsync(IRunContext run, IWorkflow workflow, } else if (result.Status == "Failed" && result.ReThrow) { - await outputRepository.AddEvent(run, workflow, action, new WorkflowFinishedEvent()); + await outputRepository.AddEvent(run, workflow, action, WorkflowEvent.CreateFinishedEvent(context.BackgroundJob.Id,result)); throw new InvalidOperationException("Action failed: " + result.FailedReason) { Data = { ["ActionResult"] = result } }; } else { - await outputRepository.AddEvent(run, workflow, action, new WorkflowFinishedEvent()); + await outputRepository.AddEvent(run, workflow, action, WorkflowEvent.CreateFinishedEvent(context.BackgroundJob.Id, result)); } } @@ -148,25 +142,26 @@ public async ValueTask ExecuteAsync(IRunContext run, IWorkflow workflow, /// /// Runs on the background process in hangfire /// - /// + /// /// - public async ValueTask TriggerAsync(ITriggerContext context) + public async ValueTask TriggerAsync(ITriggerContext triggerContext, PerformContext context) { //TODO - avoid sending all workflow over hangfire, - context.Workflow.Manifest ??= await workflowAccessor.GetWorkflowManifestAsync(context.Workflow); - - context.RunId = context.RunId == Guid.Empty ? Guid.NewGuid() : context.RunId; + triggerContext.Workflow.Manifest ??= await workflowAccessor.GetWorkflowManifestAsync(triggerContext.Workflow); - runContextAccessor.RunContext = context; - var action = await executor.Trigger(context); + triggerContext.RunId = triggerContext.RunId == Guid.Empty ? Guid.NewGuid() : triggerContext.RunId; + triggerContext.JobId = context.BackgroundJob.Id; + + runContextAccessor.RunContext = triggerContext; + var action = await executor.Trigger(triggerContext); if (action != null) { //TODO - avoid sending all workflow over hangfire, so we should wipe the workflow.manifest before scheduling and restore it after. - context.Workflow.Manifest = null; + triggerContext.Workflow.Manifest = null; var a = backgroundJobClient.Enqueue( - (executor) => executor.ExecuteAsync(context, context.Workflow, action, null)); + (executor) => executor.ExecuteAsync(triggerContext, triggerContext.Workflow, action, null)); } return action; } diff --git a/src/WorkflowEngine.Hangfire/IHangfireWorkflowExecutor.cs b/src/WorkflowEngine.Hangfire/IHangfireWorkflowExecutor.cs index b31d60d..a205d74 100644 --- a/src/WorkflowEngine.Hangfire/IHangfireWorkflowExecutor.cs +++ b/src/WorkflowEngine.Hangfire/IHangfireWorkflowExecutor.cs @@ -1,4 +1,5 @@ -using Hangfire; +using Hangfire; +using Hangfire.Server; using System.ComponentModel; using System.Threading.Tasks; using WorkflowEngine.Core; @@ -8,7 +9,7 @@ namespace WorkflowEngine public interface IHangfireWorkflowExecutor { [JobDisplayName("Trigger: {0:Workflow} RunId={0:Id}")] - public ValueTask TriggerAsync(ITriggerContext context); + public ValueTask TriggerAsync(ITriggerContext triggercontext, PerformContext context); } } diff --git a/src/WorkflowEngine.Hangfire/ScheduledWorkflowTrigger.cs b/src/WorkflowEngine.Hangfire/ScheduledWorkflowTrigger.cs index 8475afb..9466997 100644 --- a/src/WorkflowEngine.Hangfire/ScheduledWorkflowTrigger.cs +++ b/src/WorkflowEngine.Hangfire/ScheduledWorkflowTrigger.cs @@ -1,4 +1,4 @@ -using Hangfire; +using Hangfire; using Hangfire.Client; using Hangfire.Common; using Hangfire.Storage; @@ -55,7 +55,7 @@ public Task Trigger(string externalid, bool create, DateTimeOffset time, var job = _backgroundJobClient.Schedule((executor) => executor.TriggerAsync( new TriggerContext { Workflow = workflow, Trigger = trigger , - }), time); + },null), time); _logger.LogInformation("Created scheduled workflow job {JobID}", job); diff --git a/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs b/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs index 4002660..7b449c3 100644 --- a/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs +++ b/src/WorkflowEngine.Hangfire/WorkflowStarterBackgroundJob.cs @@ -1,4 +1,4 @@ -using Hangfire; +using Hangfire; using Microsoft.Extensions.Hosting; using System; using System.Collections.Generic; @@ -50,7 +50,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) Type = trigger.Value.Type, Key = trigger.Key }, - }), trigger.Value.Inputs["cronExpression"] as string); + },null), trigger.Value.Inputs["cronExpression"] as string); if (first && trigger.Value.Inputs.ContainsKey("runAtStartup") && (bool)trigger.Value.Inputs["runAtStartup"]) jobs.Trigger(workflow.Id.ToString());