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

Workflow activation strategies #3559

Merged
merged 7 commits into from
Dec 21, 2022
Merged

Workflow activation strategies #3559

merged 7 commits into from
Dec 21, 2022

Conversation

sfmskywalker
Copy link
Member

@sfmskywalker sfmskywalker commented Dec 21, 2022

This PR adds the ability for workflows to be activated only if a configured activation strategy permits so.

For example, the Singleton strategy will only allow a workflow instance to be created if there are currently no unfinished workflow instances of the same workflow definition.

To create custom strategies, simply create a class that implements IWorkflowActivationStrategy (and register it with DI) and have its method return true or false to control whether or not the workflow about to be activated should be activated or not.

Out of the box we have the following strategies:

  • Allow always - this strategy always allows a workflow to be activated.
  • Singleton - only allow the workflow to be activated if there isn't already a running instance.
  • Correlation - only allow the workflow to be activated if the correlation ID to be associated with it isn't associated with any other currently running workflow.
  • Correlated singleton - a combination of Singleton and Correlation, where the workflow may only be activated if it is not currently running.

Registered strategies are made avaialable through the UI:

image

When creating workflows from C#, simply configure the workflow's Options property with the desirered strategy type:

public class MyWorkflow : WorkflowBase
{
    protected override void Build(IWorkflowBuilder builder)
    {
        builder.WithActivationStrategyType<SingletonStrategy>();
    }
}

@sfmskywalker sfmskywalker merged commit 97b4966 into v3 Dec 21, 2022
@sfmskywalker sfmskywalker deleted the v3-singleton-workflows branch December 21, 2022 18:36
@gribunin
Copy link

It seems the activation strategy doesn't work anymore #5308

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