question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Workflow Model

See original GitHub issue

Currently, a workflow can define variables to store and retrieve state using SetVariable and GetVariable activities and methods. This works fine, but the syntax can become a bit cumbersome.

What we could have in addition is the notion of a “model” (or data or state) that is just like a variable, but available through a new strongly-typed property called Model. This would be somewhat analogous to the Model property on a Razor view.

This allows the user to define workflows that look very similar to the way it’s done in Workflow Core:

public class MyModel
{
	public string Email { get; set; }
	public string Password { get; set; }
	public string UserId { get; set; }
}

public class MyWorkflow : IWorkflow
{
    public void Build(IWorkflowBuilder<MyModel> builder)
    {    
        builder
            .StartWith<CreateUser>()
                 .With(activity => activity.Email, model=> model.Email)
                 .With(activity => activity.Password, model => model.Password)
           .Then(context => context.Model.UserId = context.Input<string>())
           .Then<SendConfirmationEmail>()
                .With(activity => activity.Email, model => model.Email)
                .With(activity => activity.UserId, model => model.UserId)
           .Then<WaitForConfirmation>()
                .With(activity => activity.UserId, model => model.UserId)
           .Then<ActivateUser>()
               .With(activity => activity.UserId, model => model.UserId);
    }
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
craigfowlercommented, Mar 2, 2021

@sfmskywalker This is very interesting, partly because it touches on something I was planning on discussing after Elsa 2.0. That’s the separation of State and Functionality within activities.

My waffling about architectural ideas

Right now anything implementing IActivity has to maintain both its own state as well as the methods like OnExecuteAsync etc. To simplify the API I was going to talk about separating those two things into two classes. There’s probably some fringe benefits too, such as making serialization easier and also reducing memory overheads because each specific activity instance is now a stateless service (so we need fewer instances).

What I had in mind was that IActivity defines only that the state of an activity is System.Object (which could be null for a stateless activity) but there would also be a generic IActivity<TState> where TState : class. Developers writing their own activities implement the generic interface and on the activity class they’re just writing the functional methods which define how the activity works. Then, for the activity state they write a small POCO model/state object.

Those functional methods (again, example is OnExecuteAsync) - in the generic version of the activity interface - would provide an instance of that model/state as an additional parameter:

ValueTask<bool> CanExecuteAsync(ActivityExecutionContext context, TState state);

Combined with some other tricks, we might be able to do away with the base Activity class altogether (and I’m a strong believer in eliminating class inheritance where possible). If consumers only need to implement an interface then their code becomes simpler and also easier to unit test (which means more chance that they will actually write them).

Triage & priority

Anyway - all of that aside - I’m going to mark this up as do later because you’ve not added it to the 2.0 milestone. I figure that means you intend to revisit this in 3.0 or later. Feel free to move to do soon if you think this should be looked-at earlier.

1reaction
zbogdanovcommented, Feb 8, 2021

Hi @sfmskywalker! First of all, thanks for all the great work you did so far.

Secondly, I’m currently evaluating Elsa for our own internal needs to power a very extendible and large set of mission-critical workflows. We decided to investigate third-party solutions when we finished the design (on paper) of our own in-house solution, and then comparing the two for requirements.

One of the most useful things for our needs is the “Workflow Context” concept, where as the workflow gets activated and starts to run, a last snapshot of the full context is retrieved from the data store and the rest is generated dynamically - creating one big model to be used by the workflow for evaluation and other needs. The context can get updated as the workflow runs also by set variable activities. Right now Elsa does not have this and this would be one of the first things we would need to extend if we decide to go with Elsa, so this feature is a great idea I think.

I’ll be keeping an eye on this PR and If we decide to go to Elsa, I’ll probably volunteer to help out with this feature if it will not be done by then.

Thanks again, keep up the fantastic work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating Workflow Models | Adobe Experience Manager
The Add Workflow Model dialog appears. Enter the Title and Name (optional) before selecting Done. The new model is listed in the Workflow...
Read more >
How to create workflows for company-managed projects?
From your project's sidebar, select Project settings > Workflows. Click Add workflow and choose Add Existing. Select your new workflow and click Next....
Read more >
Customize the workflow of an inherited process - Azure ...
Supported customizations · Impact to teams with workflow changes · Prerequisites · Open Settings>Process · Add a workflow state · Edit a state...
Read more >
Creating a custom workflow - Horizzon
In the model browser, click the Forms diagram to open it. · Add one or more forms to the diagram, and name them....
Read more >
Hub and Spoke Workflow Model Example
The Hub and Spoke workflow model allows for a central point of contact in the parent workflow (the "hub") to route things to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found