Skip to content

Instantly share code, notes, and snippets.

@sfmskywalker
Created September 11, 2020 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfmskywalker/0d6326b0f5cf4b13c542168fd8f3f488 to your computer and use it in GitHub Desktop.
Save sfmskywalker/0d6326b0f5cf4b13c542168fd8f3f488 to your computer and use it in GitHub Desktop.
Get a workflow by ID and execute it
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