In one of our project we used Azure web job which ran by scheduler and performed some periodic actions. They included Sharepoint Online CSOM calls for updating list item in Sharepoint list and Graph API calls for getting members of Azure AD group. From time to time these calls failed randomly, e.g. attempt to update list item via CSOM failed with “Version conflict” exception and Graph API calls failed with service exception without any clear error message. Both APIs are continuously evolved and calls (especially repeated calls which run frequently) may still fail with such inconsistent errors.
As workaround to make process more robust the following approach was used: make API calls in several attempts. If 1st attempt failed, wait some time and repeat call again – max number of attempts is also specified. Here is the code which demonstrates the idea:
Here we make 5 attempts to update list item – set users to User field type with multiple values (lines 21-41) with 1 sec delay between attempts (lines 5-18). In code we use it like this:
And similar approach was used for Graph API calls. After that web job runs became much more robust.