public async Task <ExportProfile> GetExportProfile(Guid profileId, CancellationToken cancellationToken) { Ensure.Guid.IsNotEmpty(profileId, nameof(profileId)); var profileTask = _profileQuery.GetProfile(profileId, cancellationToken); var photosTask = GetProfilePhotos(profileId, cancellationToken); await Task.WhenAll(profileTask, photosTask).ConfigureAwait(false); return(new ExportProfile(profileTask.Result, photosTask.Result)); }
public async Task <IActionResult> Get(CancellationToken cancellationToken) { var profileId = User.Identity.GetClaimValue <Guid>(ClaimType.ProfileId); // See Issue 35 - https://github.com/Divergic/techmentorapi/issues/35 The problem is that // the account and profile are stored separately This can cause a race condition if // multiple concurrent authenticated calls are made to the API for a new account. The // first call writes the account, then the profile. The second call will find the account // exists, but the profile may have not been created yet causing a 404 We need a retry // attempt here to ensure try to recover from this scenario This can be removed in the // future if the storage mechanism is changed to one that supports atomic transactions var profile = await Policy.HandleResult <Profile>(x => x == null) .WaitAndRetryAsync(3, x => TimeSpan.FromMilliseconds(x * 500)) .ExecuteAsync(() => _profileQuery.GetProfile(profileId, cancellationToken)).ConfigureAwait(false); if (profile == null) { return(new ErrorMessageResult(Resources.NotFound, HttpStatusCode.NotFound)); } return(new OkObjectResult(profile)); }