Friday, May 14, 2010

When do asynchronous jobs fail, suspend or retry?

 

Gonzalo Ruiz wrote an excellent article on When do asynchronous jobs fail, suspend or retry? When the CRM Asynchronous Processing Service gets an error, there are three possible actions it will take depending on the type of error:

  • Fail: Job cannot be resumed.
  • Retry: Job will be paused and retried after a period of time.
  • Suspend: Job will be suspended until it is manually resumed.

The entire error handling mechanism is rather complex but I thought of writing down some general rules that will help understanding what the outcome action will be depending on the error that occurs inside the asynchronous job:

Scenario

Async job

result action

Workflow

result action

Error code

An SDK call fails: Infinite loop detected

Fail

80044182

An SDK call fails: Organization disabled

Retry

8004A104 / 8004A107

An SDK call fails: Server is busy

Retry

8004A001

An SDK call fails: Other

Fail

Suspend

 

SQL exception is thrown

Retry

80040216

Workflow system is paused

N/A

Suspend

80045017

Network error

Retry

80044306

Record associated with workflow cannot be found

N/A

Suspend

80045031

The HTTP response fails with code HttpStatusCode.Unauthorized

Suspend

80044306

The HTTP response fails

Retry

80044306

Plugin or workflow activity throws an InvalidPluginExecutionException

Fail

80040265

Anything else

Fail

 

Please note that the table above can be used as a general guide but might not cover all scenarios, some exceptions to these actions might apply and it might go outdated in the future.

Why do workflows have a different behavior than other asynchronous jobs when an SDK call fails?

Because the user might be able to fix the problem and resume the workflow. For example, a workflow step sends an email to an account. If the account has no email address, the workflow will suspend with error message "This message cannot be sent to all selected recipients. The e-mail address for one or more recipients is either blank or not a valid e-mail address".

The user can add the email address to the account and resume the workflow. The reason why other asynchronous jobs fail instead is because while workflows are sometimes manipulated by end users, other asynchronous jobs are more oriented towards the system administrator or customizer.

When the result action is Retry, for how long will the job pause before automatically retrying and how much time is there between retries?

The "PostponeUntil" attribute of the asynchronous operation corresponds to the next time it will be retried. The “PostponeUntil” attribute can be retrieved using the SDK. The amount of time to wait until the next retry is calculated considering some deployment settings and grows exponentially on the number of retries. The calculation uses a complex algorithm but these are some default outputs as a function of the RetryCount (the number of times the operation has been retried before):

RetryCount

Time to wait (seconds)

0

36

1

43

2

52

3

62

4

75

>= 5

Suspend

Note that by default, any asynchronous operation retrying 5 or more times will be suspended.

When a job has statusreason "Waiting" and statecode "Suspended", how do I know if it will retry or if it is suspended until it is manually resumed?

You can check the "PostponeUntil" attribute of the asynchronous operation to see the time and date in which it will be automatically resumed. If this value is equal to 9999-12-30 23:59:59 (maximum DateTime value) it means that it is waiting to be manually resumed.

How can I retrieve the “PostponeUntil” attribute of the asynchronous operations?

Because the “PostponeUntil” attribute is not available from the entity form or advanced find, you will need to use the SDK to retrieve this value. The following code sample prints the date and time at which each suspended asynchronous job will resume and the number of times it has been retried.

   1: static void Main(string[] args)


   2: {


   3: CrmAuthenticationToken token = new CrmAuthenticationToken();


   4:     token.AuthenticationType = 0;


   5:     token.OrganizationName = "AdventureWorksCycle";


   6:     CrmService service = new CrmService();


   7:     service.Url = "http://crmserver/mscrmservices/2007/crmservice.asmx";


   8:     service.CrmAuthenticationTokenValue = token;


   9:     service.Credentials = System.Net.CredentialCache.DefaultCredentials;


  10:  


  11:     QueryByAttribute query = new QueryByAttribute();


  12:     query.Attributes = new string[] { "statecode" };


  13:     query.ColumnSet = new ColumnSet(new string[] { "postponeuntil", "retrycount" });


  14:     query.EntityName = EntityName.asyncoperation.ToString();


  15:     query.Values = new object[] { (int)AsyncOperationState.Suspended };


  16:     BusinessEntityCollection bec = svc.RetrieveMultiple(query);


  17:     foreach (BusinessEntity be in bec.BusinessEntities)


  18:     {


  19:         asyncoperation op = (asyncoperation)be;


  20:         string result = String.Format("Operation id={0} PostponeUntil={1} RetryCount={2}",


  21:              op.asyncoperationid.Value,


  22:              op.postponeuntil.UniversalTime,


  23:              op.retrycount.Value);


  24:         Console.WriteLine(result);




Microsoft Dynamics CRM SDK 4.0.12 Available

 

Microsoft Dynamics CRM SDK 4.0.12 is now available for download! This update contains some very exciting additions:

Advanced Developer Extensions

Advanced Developer Extensions for Microsoft Dynamics CRM, also referred to as Microsoft xRM, is a new set of tools included in the Microsoft Dynamics CRM SDK that simplifies the development of Internet-enabled applications that interact with Microsoft Dynamics CRM 4.0. It uses well known ADO.NET technologies. This new toolkit makes it easy for you to build an agile, integrated Web solution!

Advanced Developer Extensions for Microsoft Dynamics CRM supports all Microsoft Dynamics CRM deployment models: On-Premises, Internet-facing deployments (IFDs), and Microsoft Dynamics CRM Online. The SDK download contains everything you need to get started: binaries, tools, samples and documentation.

Authentication for Microsoft Dynamics CRM Online

New authentication documentation and sample code for Microsoft Dynamics CRM Online is added in this release that does not require using certificates, making it easier for you to write code for your online solutions.

There are quite a few other updates in this version of the SDK package. Refer to the release history on the first page of the CHM for a complete list.

Enjoy!

Microsoft launches the Customer Care Accelerator for Dynamics CRM 4.0

The Customer Care Accelerator (CCA) for Microsoft Dynamics CRM focuses on delivering contact center enabling functionality, such as the ability to create a unified desktop by combining data elements from disparate line of business applications and displaying it in a single user interface. The core Customer Care business scenarios highlighted by this accelerator include the following:
Integrated desktop: Customers can aggregate information from diverse business applications into an integrated desktop providing employees with a 360° view of the customer interactions. Customer service representatives have immediate access to business critical information to serve customers quickly and efficiently, increasing customer satisfaction and loyalty.
Eliminating Duplicate Data Entry: Organizations can streamline business processes by creating desktop automation workflows. Process automation eliminates the need for agents to re-enter the same data in multiple applications. Minimizing duplication helps to reduce human error and ensures a consistent customer service experience.
Computer Telephony Integration (CTI): (This is the feature I am most interested in) Organizations are provided with a consistent framework to connect CTI systems with key line of business applications. CCA provides out of the box CTI integration with the major soft and hard phone providers – many of which already have their native integration offerings to Microsoft Dynamics CRM. Also includes is integration to Bing Maps and the Office Communications server so agents can leverage an Expert on Call by opening a chat window and bring in the contextual information from the customer session into the assisted chat. The Dynamics CRM customer care accelerator also provides session management where an agent can 'park' a customer session and then come back to it.
Activity Reporting: Contact center managers have swift access to agent desktop transaction reporting, helping them to identify process bottlenecks. It Provide visibility into agent activities using out of the box and custom reports. you can download a copy to evaluate and play with it from here.