Workflow persistence for multiple workflows

This seems like an elementary question, but I can't find the answer anywhere:

I have several different types of long running state machine workflows that I work with in multiple central database applications. I am using SqlWorkflowPersistenceService to persist them. So to speak, I have three types of workflows WorkflowOne, WorkflowTwo and WorkflowThree. An instance of each of them is started and stored in the database by one user. Another user comes in and wants to make various changes, so they launch the application. Now I can use the persistence service to provide me with a list of all persisted instances, but how do I know which type of WorkflowOne is WorkflowTwo or WorkflowThree?

+2


source to share


2 answers


There are several ways to do this.

The first option is to use the WorkflowPersistenceService itself and do something like:

var persistenceService = new SqlWorkflowPersistenceService("<<connection string>>");
var persistedWorkflows = persistenceService.GetAllWorkflows();
foreach (var persistedWorkflow in persistedWorkflows)
{
    var workflowInstance = workflowRuntime.GetWorkflow(persistedWorkflow.WorkflowInstanceId);
    var workflowDefinition = workflowInstance.GetWorkflowDefinition();
    Console.WriteLine(workflowDefinition.GetType().FullName);
}

      

Easy to do since you are already using the SqlWorkflowPersistenceService, but it has the drawback of having to load all workflow instances into memory and you are responsible for removing them from memory.



The second option is to use workflow tracing:

    var trackingQuery = new SqlTrackingQuery("<<connection string>>");
    var queryOptions = new SqlTrackingQueryOptions()
    {
        WorkflowStatus = WorkflowStatus.Running
    };
    var runningWorkflows = trackingQuery.GetWorkflows(queryOptions);
    foreach (var runningWorkflow in runningWorkflows)
    {
        Console.WriteLine(runningWorkflow.WorkflowType);
    }

      

Benefit: You don't need to load the actual workflow definition into memory to check its type. The downside is that you have to add a SqlTrackingService as well as your own database adding complexity and overhead.

+4


source


Not sure if this is the best way, but I just moisten each WF instance and then compare its Name property to see what is the instance I'm looking for.



0


source







All Articles