Skip to content

Conversation

Copy link

Copilot AI commented Aug 8, 2025

This PR addresses the feedback from PR #1 by implementing a builder-style approach for configuring ForkJoin tasks, replacing the cumbersome object-based configuration with a fluent API similar to the existing DoWhile task builder.

Problem

The current ForkJoin implementation requires manually creating arrays of WorkflowTask objects, which is verbose and error-prone:

_builder.AddTask(
    wf => wf.ForkJoinTask,
    wf => new ForkJoinInput()
    {
        ForkTasks = new[]
        {
            new WorkflowTask[]
            {
                new()
                {
                    Name = "get_customer_task",
                    TaskReferenceName = "get_customer_ref",
                    Type = "SIMPLE",
                    WorkflowTaskType = WorkflowTaskType.SIMPLE,
                    InputParameters = new Dictionary<string, object> { { "customerId", wf.WorkflowInput.CustomerId } }
                }
            },
            // More manual WorkflowTask creation...
        },
        JoinOn = new[] { "get_customer_ref", "prepare_email_ref" }
    }
);

Solution

The new implementation provides a clean, fluent API that follows the established pattern from DoWhile tasks:

_builder.Fork(
    wf => wf.ForkJoinTask,
    forkBuilder =>
    {
        // First parallel branch
        forkBuilder.AddFork(taskBuilder =>
        {
            taskBuilder.AddTask(
                wf => wf.GetCustomer,
                wf => new CustomerGetV1Input { CustomerId = wf.WorkflowInput.CustomerId }
            );
        });

        // Second parallel branch  
        forkBuilder.AddFork(taskBuilder =>
        {
            taskBuilder.AddTask(
                wf => wf.PrepareEmail,
                wf => new EmailPrepareV1Input { Name = "Default", Address = "Default" }
            );
        });
    }
);

Implementation Details

  • IForkBuilder<TWorkflow>: Interface for configuring fork branches
  • ForkTaskBuilder<TWorkflow>: Main builder that extends BaseTaskBuilder and manages multiple parallel branches
  • ForkBranchBuilder<TWorkflow>: Individual branch builder implementing ITaskSequenceBuilder for task sequences
  • Fork() extension method: Entry point providing the fluent API

Key Features

  • Multiple tasks per branch: Each fork branch can contain sequential tasks
  • Automatic task reference collection: JoinOn property is automatically populated from all branch tasks
  • Full backward compatibility: Existing object-based approach continues to work
  • Consistent with existing patterns: Follows the same builder pattern as DoWhile tasks
  • Type safety: Leverages existing strongly-typed task models

Generated Output

The builder generates the same FORK_JOIN and JOIN workflow structure as the original implementation, ensuring compatibility with existing Conductor workflows.

Examples Added

  • ForkBuilderWorkflow: Basic demonstration of the new API
  • ForkJoinWorkflowNewStyle: Migration example showing old vs new approach
  • MultiBranchForkWorkflow: Advanced example with multiple tasks per branch

This enhancement significantly improves the developer experience when creating parallel workflows while maintaining full compatibility with existing code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits August 8, 2025 11:14
Co-authored-by: Roruchi <24620744+Roruchi@users.noreply.github.com>
Co-authored-by: Roruchi <24620744+Roruchi@users.noreply.github.com>
Co-authored-by: Roruchi <24620744+Roruchi@users.noreply.github.com>
Copilot AI changed the title [WIP] Can you solve the comments by adding a more builder style approach of adding the subtasks over multiple forks?. Add builder-style API for ForkJoin tasks with fluent subtask configuration Aug 8, 2025
Copilot AI requested a review from Roruchi August 8, 2025 11:26
@Roruchi Roruchi marked this pull request as ready for review August 8, 2025 11:29
@Roruchi Roruchi merged commit 3f65bdf into copilot/fix-ed05cd63-0f9d-4e0b-b2ba-8a96cf70974a Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants