LNK-4879: Fix retry ready to acquire - #1482
Conversation
* Fix Op Outcome retries * LNK-4857 * add better handling for 404 and 410 * retrigger codeql * Update PatientDataService.cs * Update PatientDataServiceTests.cs
* Update PatientDataService.cs * Update PatientDataService.cs * TECH_DEBT: Dops 487 Updating DB Migration Pipeline w/ Automation (#1332) * Updating for script * updating artifacts * updating account db deploy * Adding Windows Pool for SQL Apply * adding variable group * adding TEST environment to Apply * stashing * changing server name -> variable --------- Co-authored-by: Keith Kissal <99497673+kissalk@users.noreply.github.com>
(cherry picked from commit c0749ca)
📝 WalkthroughWalkthroughUpdates exception handling in PatientDataService to increment RetryAttempts before retrying or updating status across multiple error paths. Status transitions adjusted from Pending to Failed in certain scenarios. Corresponding test expectations updated to reflect the incremented retry count in throttling scenarios. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
DotNet/ServiceTests/IntegrationTests/DataAcquisition/PatientDataServiceTests.cs (1)
449-520: Consider adding explicit RetryAttempts assertion for OpOutcomeException tests.The
ExecuteLogRequest_HandlesOpOutcomeException_500_SetsPendingStatustest verifies the status transition toFailedbut doesn't assert thatRetryAttempts == 1. Given the PR's focus on retry tracking, adding this assertion would strengthen test coverage and prevent regression.💡 Suggested addition
// Assert Assert.NotNull(updatedModel); Assert.Equal(RequestStatus.Failed, updatedModel.Status); + Assert.Equal(1, updatedModel.RetryAttempts);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@DotNet/ServiceTests/IntegrationTests/DataAcquisition/PatientDataServiceTests.cs` around lines 449 - 520, The test ExecuteLogRequest_HandlesOpOutcomeException_500_SetsPendingStatus currently asserts the updatedModel.Status but omits verifying retry count; update the test to also assert that updatedModel.RetryAttempts == 1 (or the expected value) after the service call. Locate the UpdateDataAcquisitionLogModel captured in the updatedModel callback (set in the mock for manager.UpdateAsync) and add a simple Assert.Equal(expectedRetryCount, updatedModel.RetryAttempts) immediately after the existing Assert.Equal(RequestStatus.Failed, updatedModel.Status) to ensure retry tracking is validated for the OpOutcomeException path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@DotNet/DataAcquisition.Domain/Application/Services/PatientDataService.cs`:
- Around line 697-701: The log is currently writing raw exception text into
DataAcquisitionLog.Notes (see the log.Notes.Add call in
PatientDataService.ExecuteLogRequest), which may expose sensitive data; create
and use a sanitizer/redactor (e.g., SanitizeExceptionMessage or
RedactSensitiveInfo) to clean ex.Message and ex.InnerException?.Message (and
continue to sanitize FacilityId) before concatenation, ensure the sanitizer
strips URLs/tokens/PII and truncates length, and replace the existing direct use
of ex.Message and ex.InnerException?.Message in the log.Notes.Add call with the
sanitized outputs.
---
Nitpick comments:
In
`@DotNet/ServiceTests/IntegrationTests/DataAcquisition/PatientDataServiceTests.cs`:
- Around line 449-520: The test
ExecuteLogRequest_HandlesOpOutcomeException_500_SetsPendingStatus currently
asserts the updatedModel.Status but omits verifying retry count; update the test
to also assert that updatedModel.RetryAttempts == 1 (or the expected value)
after the service call. Locate the UpdateDataAcquisitionLogModel captured in the
updatedModel callback (set in the mock for manager.UpdateAsync) and add a simple
Assert.Equal(expectedRetryCount, updatedModel.RetryAttempts) immediately after
the existing Assert.Equal(RequestStatus.Failed, updatedModel.Status) to ensure
retry tracking is validated for the OpOutcomeException path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 52144f82-2200-4152-855f-bf3ced9a3b7d
📒 Files selected for processing (3)
DotNet/DataAcquisition.Domain/Application/Services/PatientDataService.csDotNet/ServiceTests/IntegrationTests/DataAcquisition/PatientDataServiceTests.cstests_output.txt
| log.RetryAttempts++; | ||
|
|
||
| log.ExecutionDate = DateTime.UtcNow.Add(ex.RetryAfter); | ||
| log.Status = RequestStatus.Failed; //Don't count this as a failure |
There was a problem hiding this comment.
Recommend removing the comment since we are now counting deferral as a failure.
🛠️ Description of Changes
Fixed an issue where the RetryAttempts counter was not being incremented in several failure scenarios, preventing logs from ever reaching the MaxRetriesReached state.
Modified:
DataAcquisition.Domain.Application.Services.PatientDataService:
Incremented RetryAttempts in the catch blocks for ProcessingDelayException, TooManyRequestsException (429), and general Exception.
DataAcquisition.AcquisitionWorker.Services.AcquisitionProcessorBackgroundService:
Incremented RetryAttempts when processing a work item fails.
These changes ensure that the AcquisitionProcessingJob can accurately identify logs that have exceeded the maximum number of retries (5) and move them to the MaxRetriesReached status.
🧪 Testing Performed



Updated integration tests in PatientDataServiceTests.cs to verify that RetryAttempts is incremented to 1 (from 0) when a 429 error occurs.
Executed dotnet test DotNet\ServiceTests --filter "FullyQualifiedName~PatientDataServiceTests" and verified that all 15 tests passed.
Local 251 patient test that had OperationOutcomes as well as I changed the config to a bad EHR url that simulated a retry scenario:
🧑🔬 Unit Testing
Coverage: 0.0%
I have updated unit tests to cover my changes.
📓 Documentation Updated
N/A
Summary by CodeRabbit
Bug Fixes