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

[DOC] Blocking activities has incorrect code examples #5338

Open
VijoPlays opened this issue May 3, 2024 · 4 comments
Open

[DOC] Blocking activities has incorrect code examples #5338

VijoPlays opened this issue May 3, 2024 · 4 comments
Labels
documentation Documentation is needed

Comments

@VijoPlays
Copy link

Documentation Improvement Request

Documentation Issue Overview

I've been trying to implement the Workflows according to the documentation for Blocking activities.

  1. From my testing it seems the workflow will only be paused if "context.CreateBookmark();" is the final statement. I added a Console.WriteLine afterwards and the entire workflow ran - after removing it, it only ran up to this activity. Is my assumption here correct, and if so, is there a way to suspend in the middle of the activity?
  2. Also, the line "await workflowRunner.RunAsync(workflow, workflowState, options);" is not valid, since this particular RunAsync() overload doesn't seem to exist (anymore?). There is no RunAsync function where I could provide the workflowState and I can't find any other way of resuming the Workflow.

Would be neat if these things could be fixed - and someone mention here, which method I need to use to suspend/resume a workflow. :)

@VijoPlays VijoPlays added the documentation Documentation is needed label May 3, 2024
Copy link

glime-ai bot commented May 3, 2024

  1. The behavior you're observing is consistent with the purpose of the CreateBookmark() method. When you call context.CreateBookmark(), it indicates a point where the workflow should pause and wait for an external event to resume. If you place a Console.WriteLine after CreateBookmark(), it will execute immediately because the workflow has not yet been suspended. To suspend the workflow in the middle of an activity, you should ensure that CreateBookmark() is the last call in the activity's execution path that should run before pausing.

  2. Regarding the RunAsync() method, it seems there might be a discrepancy between the documentation and the actual API. The documentation you're referring to might be outdated or incorrect. To resume a workflow, you typically need to provide a bookmark ID to the RunAsync() method. If the overload you're looking for doesn't exist, you may need to use a different method or a different overload of RunAsync() that is available in the version of Elsa you are using.

For the most accurate and up-to-date information on how to suspend and resume workflows, I recommend checking the latest official Elsa documentation or the source code directly. If the documentation is indeed outdated, you can open an issue on the Elsa GitHub repository or contact the maintainers to request an update.

For now, you can try using the WorkflowInstanceFilter to find the workflow instance and then use the RunWorkflowOptions to specify the bookmark ID when calling RunAsync(). Here's an example based on the information from the GitHub issues:

var options = new WorkflowInstanceFilter
{
    Id = InstanceId,
};
var workflowInstance = await _workflowInstanceStore.FindAsync(options);
var workflowState = workflowInstance.WorkflowState;
var bookmark = workflowState.Bookmarks.FirstOrDefault(b => /* your condition here */);
var runOptions = new RunWorkflowOptions { BookmarkId = bookmark?.Id };

var result = await _workflowRunner.RunAsync(workflow, runOptions);

Please note that the above code is just an example and may need to be adjusted based on the actual API and your specific use case.

This comment was generated by Glime.

@VijoPlays
Copy link
Author

Right, in that case the first point can be ignored (since it was mostly a question anyway).

The second point still stands and using the RunAsync method like in the example will run the entire workflow, not just resume it.

@douglasg14b
Copy link

Do you know the correct code? I'm trying to do this as well and running into trouble....

@VijoPlays
Copy link
Author

@douglasg14b their second doc worked for me: https://elsa-workflows.github.io/elsa-documentation/custom-activities.html?section=Programmatic#blocking-activities

The IWorkflowRunTime

workflowRuntime.TriggerWorkflowsAsync(activityTypeName, bookmarkPayload);

can execute the workflows again.

Only done some light testing so far, but it seems that the entire Activity is getting executed after all - instead of what's been discussed so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation is needed
Projects
None yet
Development

No branches or pull requests

2 participants