elsa-core icon indicating copy to clipboard operation
elsa-core copied to clipboard

What should we pass as a first parameter

Open TejashRaghav opened this issue 1 year ago • 3 comments

Task<RunWorkflowResult<TResult>> RunAsync<TResult>(WorkflowBase<TResult> workflow, RunWorkflowOptions? options = default, CancellationToken cancellationToken = default);

Can you provide example of above signature.

TejashRaghav avatar Mar 14 '24 11:03 TejashRaghav

Certainly! The method signature you've provided seems to be a generic method for running a workflow and obtaining a result of a specific type (TResult). Here's an example of how you might use this method:

// Define a workflow that has a result of type string
public class HelloWorldWorkflow : WorkflowBase<string>
{
    protected override void Build(IWorkflowBuilder builder)
    {
        builder.StartWith<HelloWorldActivity>()
               .Then<GoodbyeWorldActivity>()
               .Then(context => Return("The result of the workflow"));
    }
}

// Somewhere in your application, you would run the workflow like this:
var workflow = new HelloWorldWorkflow();
var workflowRunner = serviceProvider.GetRequiredService<IWorkflowRunner>();
var runOptions = new RunWorkflowOptions(); // You can specify options here if needed

// Run the workflow and get the result
var result = await workflowRunner.RunAsync<string>(workflow, runOptions, CancellationToken.None);

// Output the result of the workflow
Console.WriteLine(result.Result); // Assuming the result of the workflow is a string

In this example, HelloWorldWorkflow is a custom workflow that ends with an activity returning a string. The RunAsync method is called on an IWorkflowRunner service instance, which is typically obtained through dependency injection. The RunAsync method is awaited, and the result is captured in the result variable. The Result property of result contains the output of the workflow, which in this case is expected to be a string.

Please note that the actual implementation details may vary depending on the version of Elsa you are using and the context in which you are running workflows. The example assumes that the WorkflowBase<TResult> class and the RunAsync<TResult> method are part of the Elsa workflow library you are using.

glime-ai[bot] avatar Mar 14 '24 11:03 glime-ai[bot]

not able to resume workflow with below code

var runoption = new RunWorkflowOptions()
 {
     BookmarkId = resumeoption.BookmarkId,
     WorkflowInstanceId = InstanceId,
     CorrelationId = workflowInstance.CorrelationId
 };

 var result = await _workflowRunner.RunAsync<ProgramDetail>(newwork,runoption);

TejashRaghav avatar Mar 14 '24 12:03 TejashRaghav

@TejashRaghav Please provide detailed repro steps, then we can take a look. Thank you.

sfmskywalker avatar Apr 05 '24 22:04 sfmskywalker