Deploying of the new version of SharePoint Workflow

Deploying of the new version of SharePoint Workflow

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;
}

Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Maheshkumar S Tiwari edited Original. Comment: Added tags

Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Maheshkumar S Tiwari edited Original. Comment: Added tags

Page 1 of 1 (1 items)