public async Task <ApiLoaderWorkItem> ProcessAsync(ApiLoaderWorkItem resourceWorkItem) { var contextPrefix = LogContext.BuildContextPrefix(resourceWorkItem); var count = Interlocked.Increment(ref _count); _log.Debug($"{contextPrefix} #{count} submitting"); var refreshToken = false; while (true) { using (var response = await _poster.PostResource( resourceWorkItem.Json, resourceWorkItem.ElementName, resourceWorkItem.ResourceSchemaName, refreshToken).ConfigureAwait(false)) { if (response.StatusCode.Equals(HttpStatusCode.Unauthorized) && !refreshToken) { _log.Info("Expired token detected, refreshing and retrying request."); refreshToken = true; continue; } // if we refreshed the token we should then disable refresh token until it is needed again. if (refreshToken) { refreshToken = false; } resourceWorkItem.AddSubmissionResult(response, count); } return(resourceWorkItem); } }
public OdsApiResult AddLocalEducationAgency(Models.LocalEducationAgency newLocalEducationAgency) { var request = _mapper.Map <LocalEducationAgency>(newLocalEducationAgency); return(_restClient.PostResource(request, ResourcePaths.LocalEducationAgencies)); }