如何使用ELSA工作流引擎同步执行工作流程

发布于 2025-01-21 07:48:21 字数 118 浏览 0 评论 0原文

ELSA Workflow支持工作流的异步执行,因此我们无法将结果当作结果,线程执行的工作流执行以及立即响应。因此,完成工作流执行后,我将无法获得工作流的实际输出。因此,是否可以同步执行工作流执行,以便我可以获取最终输出。

Elsa workflow supports asynchronously execution of workflow, so we can't get the result on spot, workflow execution performed by a thread, and response back instantly. So after completing workflow execution i'm unable to get actual output of workflow. So is there any way to perform workflow execution synchronously so that I can get the final output.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见你 2025-01-28 07:48:21

您可以使用iworkflowRunner.runworkFlowAsync同步运行工作流,该返回runworkflowResult,其中包含已执行的WorkflowInstance,其中包含由输出设置的输出工作流程(如果有)。

RunWorkFlowAsync采用以下参数:

  • iworkflofllueprint - 工作流蓝图运行。
  • WorkFlowInstance - 工作流蓝图的工作流实例。
  • ActivationId - 可选。如果您的工作流程具有多个启动活动,则需要指定要使用哪个活动。
  • WorkFlowInput - 可选。如果您的工作流程期望输入,那么您就是您提供的。

要获取工作流蓝图,请使用iworkflowRegistry按名称或类型查找工作流(如果您使用Fluent API构建工作流程,则更方便。

例如,如果您有一个名为“ Helloworld”的工作流,这就是您获得工作流蓝图的方式:

var workflowBlueprint = await _workflowRegistry.FindByNameAsync("HelloWorld", VersionOptions.Published);

创建一个工作流实例,尽管您可以简单地使用其构造函数实例化新的WorkflowInstance,这是最简单的方法是要使用iWorkflowFactory像这样:

var workflowInstance = await _workflowFactory.InstantiateAsync(workflowBlueprint);

使用Ready的WorkFlow蓝图和WorkFlow实例,您现在可以运行工作流程:

var result = await _workflowRunner.RunWorkflowAsync(workflowBlueprint, workflowInstance);

作为此低级工作流程执行的替代方案,您也可以使用一项一项艰巨的高级服务。

例如,如果您使用Fluent API(即iWorkflow实现)创建了一个工作流,称为helloworldworkflow,则可以使用ibuildsandStartsworksworkflow ,这样:

var result = await _buildsAndStartsWorkflow.BuildAndStartWorkflowAsync<HelloWorldWorkflow>();

这将完成我之前为您解释的步骤(并同步运行工作流程)。

另一种方法是使用称为iworkflowlaunchpad的高级服务,该服务具有各种方法来定位要执行的工作流(或工作流)。

例如,如果您知道要同步执行的工作流定义ID,则是这样做的方法:

var myWorkflowDefinitionId = "...";
var result = await _workflowLaunchpad.FindAndExecuteStartableWorkflowAsync(myWorkflowDefinitionId);

You can run your workflow synchronously using IWorkflowRunner.RunWorkflowAsync, which returns a RunWorkflowResult that contains the executed WorkflowInstance, which contains output that was set by the workflow, if any.

The RunWorkflowAsync takes the following parameters:

  • IWorkflowBlueprint - the workflow blueprint to run.
  • WorkflowInstance - a workflow instance of the workflow blueprint.
  • ActivityId - Optional. If your workflow has more than one starting activity, you need to specify which one to use.
  • WorkflowInput - Optional. If your workflow expects input, this is where you provide it.

To get a workflow blueprint, use IWorkflowRegistry to find a workflow by name or by type (which is more convenient in case you have your workflow built using the fluent API).

For example, if you have a workflow named "HelloWorld", this is how you get the workflow blueprint:

var workflowBlueprint = await _workflowRegistry.FindByNameAsync("HelloWorld", VersionOptions.Published);

To create a workflow instance, although you could simply instantiate a new WorkflowInstance using its constructor, the simplest way is to use IWorkflowFactory like this:

var workflowInstance = await _workflowFactory.InstantiateAsync(workflowBlueprint);

With both the workflow blueprint and workflow instance at the ready, you can now run the workflow:

var result = await _workflowRunner.RunWorkflowAsync(workflowBlueprint, workflowInstance);

As an alternative to this low-level prepping of workflow execution, you can also use a higher-level service that does all this on one go.

For example, if you have a workflow created using the fluent API (i.e. some IWorkflow implementation) called HelloWorldWorkflow, then you can run the workflow using IBuildsAndStartsWorkflow, like this:

var result = await _buildsAndStartsWorkflow.BuildAndStartWorkflowAsync<HelloWorldWorkflow>();

That will do the steps I explained earlier for you (and run the workflow synchronously).

Yet another way is to use the higher-level service called IWorkflowLaunchpad, which has various methods to locate the workflow (or workflows) you want to execute.

For example, if you know the workflow definition ID you want to execute synchronously, here's how you would do it:

var myWorkflowDefinitionId = "...";
var result = await _workflowLaunchpad.FindAndExecuteStartableWorkflowAsync(myWorkflowDefinitionId);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文