Deploying of the new version of SharePoint Workflow

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

Assume you have an activity which is executing for very long time. This is so called Long-Running workflow. In fact long-running scenario is one of scenarios in Commuter Sciences which practically can very easy be solved by Using Microsoft Workflow Foundation.
Following workflow show never ending workflow which is often used in Integration scenarios where some kind of listening or long-polling need to be implemented.
image

The question in this post is: “After this workflow is started, what happens with this workflow when SharePoint deploys the new version?”. This is usually the case when some bug has been fixed or some new feature has been implemented.
During deployment of the new version SharePoint will not take a care about running instances. Instead, all running instances of the version N will be terminated with following error: 

The instance has been terminated because the workflow associated with this instance is no longer available.

After this has happened, the new version N+1 is (should be) deployed and ready to start. Currently it is not clear  (to me at least) if there is a way at all in SharePoint to figure out such issues. Fortunately Workflow Manager provides way to figure out such issues. 
Following code shows how we do that. Just call enlistInstancesInState(…) to obtain all workflows in specified state.

        private static void enlistInstancesInState(WorkflowInstanceStatus status)
        {

                enlistAllScopes(null, (client) =>
                {
                    var cnt = client.Instances.GetCount();
                    if (cnt > 0)
                    {
                        foreach (var wfInst in client.Instances.Get(0, cnt))
                        {

                            if (WorkflowInstanceStatus.NotSpecified != status && wfInst.WorkflowStatus == status)
                                traceOutWorkflow(wfInst);

                            else if (WorkflowInstanceStatus.NotSpecified == status)
                                traceOutWorkflow(wfInst);
                        }
                    }
                });
        }

      


       
/// <summary>
        /// Enlists all scopes starting at root.
        /// </summary>
        /// <param name="scopeRoot">Scope to be enlisted.</param>
        private static void enlistAllScopes(WorkflowManagementClient client, Action<WorkflowManagementClient> action)
        {

            if(client == null)
                client = getWfMgmClient(null);

            if (action != null)
                action(client);

 

            var scopes = client.CurrentScope.GetChildScopes();

 

            foreach (var childScope in scopes)
            {
                enlistAllScopes(getWfMgmClient(Path.Combine(m_Root.TrimEnd('/') + childScope.Path)), action);
            }
        }

 

 

        /// <summary>
        /// Creates the instance of the WF-client.
        /// </summary>
        private static WorkflowManagementClient getWfMgmClient(string scope)
        {

            WorkflowManagementClient client;

 

            if (scope == null)
                client = new WorkflowManagementClient(m_Root);
            else
                client = new WorkflowManagementClient(scope);

 

            return client;
        }

 

Posted Dec 04 2012, 08:58 AM by Damir Dobric
developers.de is a .Net Community Blog powered by daenet GmbH.