Skip to content

Commit 3d85d29

Browse files
committed
fix: made the queue propergate when triggering new actions
1 parent fa4d37e commit 3d85d29

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

src/WorkflowEngine.Core/ActionImplementationMetadata.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class ActionImplementationMetadata
1010
public string Type { get; set; }
1111
public Type Implementation { get; protected set; }
1212

13+
14+
1315
public static IActionImplementationMetadata FromType(Type type, string name)
1416
{
1517
var metadata = Activator.CreateInstance(typeof(ActionImplementationMetadata<>).MakeGenericType(type)) as ActionImplementationMetadata;
@@ -39,14 +41,10 @@ public async ValueTask<ActionResult> ExecuteAsync(IServiceProvider services, IRu
3941

4042
var actionResult = await implementation.ExecuteAsync(context, workflow, action);
4143

42-
var result = new ActionResult
43-
{
44-
Key = action.Key,
45-
Status = "Succeded",
46-
Result = actionResult,
47-
DelayNextAction = (implementation is IWaitAction) ? (TimeSpan) actionResult : null
48-
};
49-
return result;
44+
return ActionResult.Success(action, actionResult,implementation);
45+
46+
47+
5048
}
5149
}
5250

@@ -69,14 +67,8 @@ public async ValueTask<ActionResult> ExecuteAsync(IServiceProvider services, IRu
6967

7068
var actionResult= await implementation.ExecuteAsync(context, workflow, typedAction);
7169

72-
var result = new ActionResult
73-
{
74-
Key = action.Key,
75-
Status = "Succeded",
76-
Result = actionResult,
77-
DelayNextAction = (implementation is IWaitAction) ? (TimeSpan) actionResult : null
78-
};
79-
return result;
70+
return ActionResult.Success(action, actionResult, implementation);
71+
8072
}
8173
}
8274

src/WorkflowEngine.Core/ActionResult.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using static System.Collections.Specialized.BitVector32;
23

34
namespace WorkflowEngine.Core
45
{
@@ -11,6 +12,18 @@ public class ActionResult : IActionResult
1112
public string FailedReason { get; set; }
1213
public bool ReThrow { get; set; }
1314
public TimeSpan? DelayNextAction { get; set; }
15+
16+
public static ActionResult Success(IAction action, object actionResult, object implementation)
17+
{
18+
var result = new ActionResult
19+
{
20+
Key = action.Key,
21+
Status = "Succeded",
22+
Result = actionResult,
23+
DelayNextAction = (implementation is IWaitAction) ? (TimeSpan) actionResult : null
24+
};
25+
return result;
26+
}
1427
}
1528

1629

src/WorkflowEngine.Hangfire/HangfireWorkflowExecutor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ public HangfireWorkflowExecutor(IWorkflowAccessor workflowAccessor, IHangfireAct
8686
public async ValueTask<object> ExecuteAsync(IRunContext run, IWorkflow workflow, IAction action, PerformContext context)
8787
{
8888
try
89-
{
89+
{
9090
runContextAccessor.RunContext = run;
9191
arrayContext.JobId = context.BackgroundJob.Id;
92-
92+
var queue = context.BackgroundJob.Job.Queue ?? "default";
9393

9494
var result = await actionExecutor.ExecuteAsync(run, workflow, action);
9595

@@ -109,12 +109,12 @@ public async ValueTask<object> ExecuteAsync(IRunContext run, IWorkflow workflow,
109109
if (result.DelayNextAction.HasValue)
110110
{
111111

112-
var workflowRunId = backgroundJobClient.Schedule<IHangfireActionExecutor>(
112+
var workflowRunId = backgroundJobClient.Schedule<IHangfireActionExecutor>(queue,
113113
(executor) => executor.ExecuteAsync(run, workflow, next, null),result.DelayNextAction.Value);
114114
}
115115
else
116116
{
117-
var workflowRunId = backgroundJobClient.Enqueue<IHangfireActionExecutor>(
117+
var workflowRunId = backgroundJobClient.Enqueue<IHangfireActionExecutor>(queue,
118118
(executor) => executor.ExecuteAsync(run, workflow, next, null));
119119
}
120120

@@ -133,14 +133,14 @@ public async ValueTask<object> ExecuteAsync(IRunContext run, IWorkflow workflow,
133133
if (result.DelayNextAction != null)
134134
{
135135

136-
var workflowRunId = backgroundJobClient.Schedule<IHangfireActionExecutor>(
136+
var workflowRunId = backgroundJobClient.Schedule<IHangfireActionExecutor>(queue,
137137
(executor) => executor.ExecuteAsync(run, workflow, scopeAction, null),result.DelayNextAction.Value);
138138
}
139139
else
140140
{
141141

142142

143-
var workflowRunId = backgroundJobClient.Enqueue<IHangfireActionExecutor>(
143+
var workflowRunId = backgroundJobClient.Enqueue<IHangfireActionExecutor>(queue,
144144
(executor) => executor.ExecuteAsync(run, workflow, scopeAction, null));
145145
}
146146
//await outputRepository.EndScope(run, workflow, action);
@@ -177,8 +177,8 @@ public async ValueTask<object> TriggerAsync(ITriggerContext triggerContext)
177177
/// <param name="triggerContext"></param>
178178
/// <returns></returns>
179179
public async ValueTask<object> TriggerAsync(ITriggerContext triggerContext, PerformContext context = null)
180-
{
181-
180+
{
181+
var queue = context.BackgroundJob.Job.Queue ?? "default";
182182
triggerContext.RunId = triggerContext.RunId == Guid.Empty ? Guid.NewGuid() : triggerContext.RunId;
183183
triggerContext.JobId = context?.BackgroundJob.Id;
184184

@@ -187,7 +187,7 @@ public async ValueTask<object> TriggerAsync(ITriggerContext triggerContext, Perf
187187

188188
if (action != null)
189189
{
190-
var a = backgroundJobClient.Enqueue<IHangfireActionExecutor>(
190+
var a = backgroundJobClient.Enqueue<IHangfireActionExecutor>(queue,
191191
(executor) => executor.ExecuteAsync(triggerContext, triggerContext.Workflow, action, null));
192192
}
193193
return action;

0 commit comments

Comments
 (0)