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

[Question] What does the option UseMaxConcurrentWorkflows do? #1274

Open
felix2000jp opened this issue Jun 13, 2024 · 0 comments
Open

[Question] What does the option UseMaxConcurrentWorkflows do? #1274

felix2000jp opened this issue Jun 13, 2024 · 0 comments

Comments

@felix2000jp
Copy link

Hi!

I am trying to implement workflow core in an existing system and one of the requirements is to be possible for x number workflows to run concurrently.

At first glance I though that the option UseMaxConcurrentWorkflows could achieve this, but after some testing I realized that this options controls how many steps run concurrently and not how many workflows.

This is the code I am using for testing this behavior:

// Workflow registration - I am using prostgres for persistance and redis for queue
// also for this example I set UseMaxConcurrentWorkflows to 2
builder.Services.AddWorkflow(options =>
{
    options.EnableLifeCycleEventsPublisher = true;
    options.EnableWorkflows = true;
    options.EnablePolling = true;
    options.EnableIndexes = true;
    options.EnableEvents = true;
    options.UseMaxConcurrentWorkflows(2);
    
    options.UsePostgreSQL(databaseConnectionString, true, true);
    options.UseRedisLocking(queueConnectionString);
    options.UseRedisQueues(queueConnectionString, "api-queue");
    options.UseRedisEventHub(queueConnectionString, "api-channel");
});
// The example workflow I am testing with with only 3 steps
public class WorkflowA : IWorkflow<ContextA>
{
    public string Id => "WorkflowA";
    public int Version => 1;

    public void Build(IWorkflowBuilder<ContextA> builder)
    {
        builder
            .StartWith<StepA1>()
            .Then<StepA2>()
            .Then<StepA3>();
    }
}
// each step does the same thing - they delay the execution for some time (3 seconds) and then move on
public abstract class BaseStep : IStepBody
{
    public async Task<ExecutionResult> RunAsync(IStepExecutionContext context)
    {
        var workflowContext = (ContextA)context.Workflow.Data;

        await Task.Delay(TimeSpan.FromSeconds(workflowContext.StepExpectedDurationInSeconds));
        return ExecutionResult.Next();
    }
}

Let's say that over the course of 5 seconds every second I send a request to my app that starts a new WorkflowA.

I expect that the first two requests will add two workflows to the queue and these will run concurrently to the end and then start the next two workflows in the queue.

Instead, the queue does not have workflow but steps, and it only runs the first step in two workflows and then sends step 2 to the end of the queue. In my real use case this means that step 2 will sometimes run hours after step 1 was finished (since we are always receiving new requests to start new workflows) and this is a problem.

Is this the default behavior or am I misconfiguring something? And if it is default behavior, are there options available to customize this?

@felix2000jp felix2000jp changed the title [Question] What exactly does the option UseMaxConcurrentWorkflows affect? [Question] What does the option UseMaxConcurrentWorkflows do? Jun 13, 2024
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

No branches or pull requests

1 participant