Monday, April 20, 2015

SharePoint workflow timer job stuck in paused status - Steps to resolve the issue



If you have worked on SharePoint 2010 long enough, you might notice that SharePoint Workflow Timer Job might stuck at 0% and paused. This could happen on SharePoint 2010 and 2013 for version 2010 workflows. You could follow the steps below to resolve the issue.

  1. Stop Timer service, clean up timer job cache, and restart Timer service as most people suggested.
  2. If this is not working, you might need to tune the workflow configuration to improve the performance.
  3. Cleanup BAD workflows both definitions and instances

Most people could resolve the issues after step 1 and 2. However in our case, we are still constantly having the workflow job paused issue.  Here are some major contributors to this issue.


  • Workflow approval include users who are no longer in the company. The users are removed form AD and workflow failed to start while validating the users.  
  • Workflow notifier include users who are no longer in the company. The users are removed form AD and SharePoint might constantly fail to send the email. This will cause SMTP email stability also.
  • Workflow author or editor include users who are no longer in the company. This does not seem to cause problem as we tested. It might be a good practice to publish them workflows using the valid AD users.
  • Workflow instance without valid workflow definition. The workflow definition removed by users.

You should also review how the workflows used by the end users.  We have a workflow configured to the discussion board and each discussion thread with each attachment will trigger the workflow. It will also create the task list. You can image how many instances will be trigger  on this discussion board!

There are different reports we are developing will help us to identify the workflows that have the issues listed above. One of the key report is the list failed workflows. The "Workflow failover" timer job will continue retry every 15 minutes as default to process failed workflows. If you have increasing number failed workflows, this timer job will have larger and increasing load. Evenmtually, it will failed to handle the load.

Here is the script to report failed workflow for your reference. We have other workflow reports coming soon.

#**************************************************************************************
# Input Arguments
#**************************************************************************************
param()
$startTime = Get-Date

# param()
#**************************************************************************************

#**************************************************************************************
# References and Snapins
#**************************************************************************************
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
            Add-PSSnapin Microsoft.SharePoint.PowerShell
}          
#**************************************************************************************

#**************************************************************************************
# References and Snapins
#**************************************************************************************
$reportFile = $myinvocation.mycommand.path.Replace($MyInvocation.MyCommand.name,"") + 'Report_WorkflowActivityUsage_' + $(Get-Date -format "dd_MM_yyyy_HH_mm_ss") + '.csv';
$rows = @();

$line = "WebsiteURL" + “,” + "ItemUrl"  + “,” + "WorkflowAssociateName" + “,” + "Workflow Status" + “,” + "WorkfflowModified" + “,” + "WorkfflowAuther" + “,” + "WorkfflowId"
Add-Content $reportFile $line
#**************************************************************************************

#**************************************************************************************
# Primary Statement Blocks
#**************************************************************************************
cls


$contentWebAppServices = (Get-SPFarm).services |? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}

foreach($webApp in $contentWebAppServices.WebApplications)
{

    foreach ($siteColl in $webApp.Sites)
    {

        Write-Host "Now Working on Site Collection: $($siteColl.Url)";
        try{
            foreach($spSite in $siteColl)
            {

                    $assignmentCollection = Start-SPAssignment
                    foreach($spWeb in $spSite.AllWebs)
                    {

                            foreach ($list in $spWeb.Lists)
                            {

                              if ($list.WorkflowAssociations.Count -gt 0)
                              {
                                    foreach ($item in $list.Items)
                                    {
                                        foreach ($workfflow in $item.Workflows)
                                        {
                                                if ($workfflow.ParentAssociation.Name -notlike "*Previous Version*")
                                                    {

                                                        $line = $spWeb.Url + “,” + '"' + $item.Url  + '"' + “,” + '"' + $workfflow.ParentAssociation.Name + '"' + “,” + '"' + $workfflow.InternalState + '"'+ “,” + '"' + $workfflow.Modified.ToShortDateString()  + '"' + “,” + '"' + $workfflow.Author  + '"' + “,” + '"' + $workfflow.ParentAssociation.Id  + '"'
                                                        Add-Content $reportFile $line
                                                    }
                                        }
                                    }
                                }

                            }
       
                    }

                    Stop-SPAssignment $assignmentCollection
                    #http://blog.ithinksharepoint.com/2014/06/02/powershell-sharepoint-and-memory-leaks-start-spassignment/

            }
        }catch{}

    }

}

$endTime = Get-Date
#Write-Host "Time after:" $b -ForegroundColor Green

Write-Host -ForegroundColor Yellow "Processed the script in $(($endTime-$startTime).TotalSeconds) seconds .......";


If you have any input to handle the paused workflow issue, please share. We might plan to implement SharePoint 2013 workflow to improve the scalability of the workflow.

 




 

1 comment:

  1. Hi,
    What type of script is this and where do you implement it?
    Thanks for the post!

    ReplyDelete