Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sync failure state exception handling #1656

Closed

Conversation

ellykits
Copy link
Collaborator

@ellykits ellykits commented Oct 7, 2022

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #1654

Description
Clear and concise code change description.

Type
Choose one: Bug fix

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@@ -30,16 +30,17 @@ import org.hl7.fhir.r4.model.ResourceType
class DownloadWorkManagerImpl : DownloadWorkManager {
private val resourceTypeList = ResourceType.values().map { it.name }
private val urls = LinkedList(listOf("Patient?address-city=NAIROBI"))
override var nextRequestUrl: String? = null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make it private. ideally this should not be modifiable outside this class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. This was exposed to be used in com.google.android.fhir.sync.download.DownloaderImpl#download to get the resource type that is currently being synced. The catch operator can only access the flow instance and not the internal states within the flow { } closure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the resource type in ResourceSyncException data class? Most instance creation of that class have ResourceType.Bundle provided as the resource type.

Copy link
Collaborator

@maimoonak maimoonak Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it does emit the failed resource type. the test DownloaderImplTest.downloader with patient and observations should continue to download observations if patient download fail has an assertion for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigating the failing tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured the cause of the filing tests. So apparently the catch operator completes the flow thus the remaining states are not emitted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was verifying whether emissions still happens even when there is a failure. Which I think should be the correct behavior. I will revert and remove the emission in the catch section of the try-catch block.

.catch { throwable: Throwable ->
Timber.e(throwable, "Error saving remote resource to database")
}
.collect()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using on each and doing the processing above. do we need collect now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes collect operator is required to process all emitted values and handle exceptions that might occur in the upstream flow or during processing.

@ellykits
Copy link
Collaborator Author

@maimoonak I will have to revert the commits; then create a new PR instead of maintaining the commit history of reverted code.

@ellykits ellykits closed this Oct 17, 2022
@ellykits ellykits mentioned this pull request Oct 17, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Download fails to complete when exception is encountered
2 participants