Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying human task output #191

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ConductorSharp.Engine/Builders/HumanTaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ namespace ConductorSharp.Engine.Builders
{
public static class HumanTaskExtensions
{
public static ITaskOptionsBuilder AddTask<TWorkflow>(
public static ITaskOptionsBuilder AddTask<TWorkflow, TOutput>(
this ITaskSequenceBuilder<TWorkflow> builder,
Expression<Func<TWorkflow, HumanTaskModel>> reference,
Expression<Func<TWorkflow, HumanTaskInput>> input
Expression<Func<TWorkflow, HumanTaskModel<TOutput>>> reference,
Expression<Func<TWorkflow, HumanTaskInput<TOutput>>> input
)
where TWorkflow : ITypedWorkflow
{
var taskBuilder = new HumanTaskBuilder(reference.Body, input.Body, builder.BuildConfiguration);
var taskBuilder = new HumanTaskBuilder<TOutput>(reference.Body, input.Body, builder.BuildConfiguration);
builder.AddTaskBuilderToSequence(taskBuilder);
return taskBuilder;
}
}

internal class HumanTaskBuilder(Expression taskExpression, Expression inputExpression, BuildConfiguration buildConfiguration)
: BaseTaskBuilder<HumanTaskInput, NoOutput>(taskExpression, inputExpression, buildConfiguration)
internal class HumanTaskBuilder<TOutput>(Expression taskExpression, Expression inputExpression, BuildConfiguration buildConfiguration)
: BaseTaskBuilder<HumanTaskInput<TOutput>, TOutput>(taskExpression, inputExpression, buildConfiguration)
{
public override WorkflowTask[] Build() =>
[
Expand Down
4 changes: 2 additions & 2 deletions src/ConductorSharp.Engine/Model/HumanTaskModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ConductorSharp.Engine.Model
{
public class HumanTaskInput : IRequest<NoOutput> { }
public class HumanTaskInput<TOutput> : IRequest<TOutput> { }

public class HumanTaskModel : TaskModel<HumanTaskInput, NoOutput> { }
public class HumanTaskModel<TOutput> : TaskModel<HumanTaskInput<TOutput>, TOutput> { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<None Remove="Samples\Workflows\DynamicTask.json" />
<None Remove="Samples\Workflows\EvaluateExpressionWorkflow.json" />
<None Remove="Samples\Workflows\EventTaskWorkflow.json" />
<None Remove="Samples\Workflows\HumanTask.json" />
<None Remove="Samples\Workflows\HumanTaskWorkflow.json" />
<None Remove="Samples\Workflows\IndexerWorkflow.json" />
<None Remove="Samples\Workflows\ListInitializationWorkflow.json" />
<None Remove="Samples\Workflows\NestedObjects.json" />
Expand All @@ -39,7 +39,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Samples\Workflows\HumanTask.json" />
<EmbeddedResource Include="Samples\Workflows\HumanTaskWorkflow.json" />
<EmbeddedResource Include="Samples\Workflows\ListInitializationWorkflow.json" />
<EmbeddedResource Include="Samples\Workflows\EvaluateExpressionWorkflow.json" />
<EmbeddedResource Include="Samples\Workflows\TaskPropertiesWorkflow.json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void BuilderReturnsCorrectDefinitionPassthroughTaskWorkflow()
public void BuilderReturnsCorrectDefinitionHumanWorkflow()
{
var definition = GetDefinitionFromWorkflow<HumanTaskWorkflow>();
var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile("~/Samples/Workflows/HumanTask.json");
var expectedDefinition = EmbeddedFileHelper.GetLinesFromEmbeddedFile("~/Samples/Workflows/HumanTaskWorkflow.json");

Assert.Equal(expectedDefinition, definition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ public class HumanTaskWorkflowOutput : WorkflowOutput { }

public class HumanTaskWorkflow : Workflow<HumanTaskWorkflow, HumanTaskWorkflowInput, HumanTaskWorkflowOutput>
{
public HumanTaskModel HumanTask { get; set; }
public class HumanTaskOutput
{
public string CustomerId { get; set; }
}

public HumanTaskModel<HumanTaskOutput> HumanTask { get; set; }
public CustomerGetV1 GetCustomer { get; set; }

public HumanTaskWorkflow(WorkflowDefinitionBuilder<HumanTaskWorkflow, HumanTaskWorkflowInput, HumanTaskWorkflowOutput> builder)
: base(builder) { }
Expand All @@ -22,6 +28,7 @@ public override void BuildDefinition()
base.BuildDefinition();

_builder.AddTask(wf => wf.HumanTask, wf => new() { });
_builder.AddTask(wf => wf.GetCustomer, wf => new() { CustomerId = wf.HumanTask.Output.CustomerId });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
"inputParameters": {},
"type": "HUMAN",
"workflowTaskType": "HUMAN"
},
{
"name": "CUSTOMER_get",
"taskReferenceName": "get_customer",
"inputParameters": {
"customer_id": "${human_task.output.customer_id}"
},
"type": "SIMPLE",
"optional": false,
"workflowTaskType": "SIMPLE"
}
],
"inputParameters": [],
Expand Down
Loading