Windows 工作流:“单例”式工作流?

发布于 2024-07-24 16:17:49 字数 315 浏览 3 评论 0原文

我有一个工作流程,它将监视某些数据库并在注意到触发器时启动其他工作流程。 我只希望这个“观察者”工作流程的一个实例在任何时间点运行; 否则,如果两个或多个正在运行,它们都会注意到更改,并且都会启动相同的工作流程,这将无法正常工作。

此“观察者”工作流程将持续存在。 那么...我该如何做到这一点,以便如果运行时还没有保存此工作流的实例,它会启动一个实例,但如果已经存在,则只需使用保存的实例?

听起来我几乎可以创建一个小型的运行一次控制台应用程序来启动我想要的工作流程,然后“真正的”运行时只是拉出持久的工作流程,并且从不尝试创建新的工作流程,但这听起来不太优雅。

I have a workflow that will watch certain databases and kick off other workflows when it notices a trigger. I only want one instance of this "observer" workflow to be going at any point in time; otherwise, if two or more were running, they'd both notice the change and both fire off the same workflow, which wouldn't work well.

This "observer" workflow is persisted. So...how do I make it so that if the runtime doesn't have an instance of this workflow persisted already, it starts one, but if one is already there, just use the persisted one?

Almost sounds like I could create a small run-once console app that kicked off the workflow I wanted, and then the "real" runtime just pulled the persisted one and never tries to create a new one, but that doesn't sound very elegant.

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

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

发布评论

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

评论(2

-残月青衣踏尘吟 2024-07-31 16:17:49

我正在为我目前正在进行的一个项目考虑这个问题。 然而,在我看来,监视数据库的功能不是工作流程的职责。

我们将创建一个服务来添加到运行时。 该服务将引发工作流在 HandleEventActivity 中侦听的事件。 这样,工作流程就会闲置、持久并保持这种状态,直到真正需要执行实际工作为止。

I'm considering this problem as well for a project I'm currently working. However it seems to me that the function of monitoring the DB is not the responsibilty of the workflow.

We're going to create a Service to add to the runtime. This service will raise events that the workflow listens for in the HandleEventActivity. That way the workflow goes idle, is persisted and stays that way until a real work actually needs doing.

偏爱自由 2024-07-31 16:17:49

前段时间我们在一个项目中遇到了这个问题。 我们提出的解决方案是托管两个运行时; 一种有持久性服务,一种没有。 在没有持久性服务的运行时中,我们运行了几个这种“监视工作流程”,这些工作流程在主机启动时自动启动。

这就是它的实现方式:

首先,我们有一个配置文件,在其中设置持久性服务:

<configuration>
    <configSections>
        <section name="RuntimeWithPersistence" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </configSections>
    <RuntimeWithPersistence>
        <CommonParameters/>
        <Services>
            <add type="System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionString="[dbconnectionstring]" UnloadOnIdle="true"/>
        </Services>
    </RuntimeWithPersistence>
</configuration>    

在工作流主机应用程序中(剪切和编辑,但我想我传达了这个想法):

public class WorkflowHost
{
    private WorkflowRuntime _runtime = null;
    private WorkflowRuntime _nonPersistingRuntime = null;

    private void SetupRuntime()
    {
        // create a new WorkflowRuntime that points out a config section
        // defining a persistence service
        _runtime = new WorkflowRuntime("RuntimeWithPersistence");
        // set up additional services to use
        _runtime.StartRuntime()

        // create a new WorkflowRuntime that does not point out a config section
        _nonPersistingRuntime = new WorkflowRuntime();
        // set up additional services to use
        _nonPersistingRuntime.StartRuntime()
        // start monitoring workflows in the non persisting runtime
        StartMonitoringWorkflows(_nonPersistingRuntime);
    }
}

We had this problem in a project a while ago. The solution we came up with was to host two runtimes; one with persistence services and one without. In the runtime with no persistence service we were running a couple of this kind of "monitoring workflows" that were automatically started when the host was started.

This is how it was implemented:

First, we had a config file in which we set up the persistence service:

<configuration>
    <configSections>
        <section name="RuntimeWithPersistence" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </configSections>
    <RuntimeWithPersistence>
        <CommonParameters/>
        <Services>
            <add type="System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            <add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionString="[dbconnectionstring]" UnloadOnIdle="true"/>
        </Services>
    </RuntimeWithPersistence>
</configuration>    

And in the workflow host application (cut and edited, but I think i communicates the idea):

public class WorkflowHost
{
    private WorkflowRuntime _runtime = null;
    private WorkflowRuntime _nonPersistingRuntime = null;

    private void SetupRuntime()
    {
        // create a new WorkflowRuntime that points out a config section
        // defining a persistence service
        _runtime = new WorkflowRuntime("RuntimeWithPersistence");
        // set up additional services to use
        _runtime.StartRuntime()

        // create a new WorkflowRuntime that does not point out a config section
        _nonPersistingRuntime = new WorkflowRuntime();
        // set up additional services to use
        _nonPersistingRuntime.StartRuntime()
        // start monitoring workflows in the non persisting runtime
        StartMonitoringWorkflows(_nonPersistingRuntime);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文