Created
September 11, 2020 18:51
-
-
Save sfmskywalker/0d6326b0f5cf4b13c542168fd8f3f488 to your computer and use it in GitHub Desktop.
Get a workflow by ID and execute it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Elsa.Models; | |
using Elsa.Services; | |
using Elsa.Services.Models; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace Sample | |
{ | |
public class RunSomeWorkflow | |
{ | |
private readonly IWorkflowRegistry _workflowRegistry; | |
private readonly IServiceProvider _provider; | |
public StartWorkflowHandler(IWorkflowRegistry workflowRegistry, IWorkflowInvoker invoker) | |
{ | |
_workflowRegistry = workflowRegistry; | |
_invoker = invoker; | |
} | |
public async Task<WorkflowExecutionContext> RunWorkflowAsync(string workflowId, CancellationToken cancellationToken) | |
{ | |
var workflow = await _workflowRegistry.GetWorkflowDefinitionAsync(workflowId, VersionOptions.Published, cancellationToken); | |
if(workflow != null) | |
{ | |
return await _invoker.StartAsync(workflow); | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment