-
Notifications
You must be signed in to change notification settings - Fork 243
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: out bound push fails while writing to info doc #9855
base: master
Are you sure you want to change the base?
Conversation
d4cb07e
to
4c8d02b
Compare
@jonathanbataire I'm happy to review this when it's ready! Please let me know :) |
ready for review @dianabarsan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really appreciate you resolving on this! I left one suggestion inline.
@@ -48,8 +48,17 @@ const markForOutbound = (change) => { | |||
.then(sent => { | |||
if (sent) { | |||
// Successfully sent, outbound.send wrote to the infodoc | |||
|
|||
return db.sentinel.put(change.info); | |||
return db.sentinel.get(change.info._id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this conflict resolution is a bit verbose to be here, and it doesn't treat an eventual conflict directly - in your error, the status that the PUT request got was 409, and here you're only resolving for 404s (not found).
I think the best solution here is to use the infodoc
shared lib, which already has infodoc conflct resolution built in and already has a saveCompletedTasks
function (https://github.com/medic/cht-core/blob/master/shared-libs/infodoc/src/infodoc.js#L285). This function doesn't receive parameters now, but that can be changed.
Please let me know what you think!
@@ -133,6 +133,78 @@ describe('mark_for_outbound', () => { | |||
}); | |||
}); | |||
|
|||
it('correctly creates and sends multiple outbound requests for the same report immediately', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this test!
shared-libs/infodoc/src/infodoc.js
Outdated
@@ -156,7 +156,7 @@ const saveTransitions = change => { | |||
}; | |||
|
|||
const saveCompletedTasks = (id, infodoc) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to add a parameter here, to save correct completed_tasks, instead of just completing all tasks.
@@ -155,8 +155,8 @@ const saveTransitions = change => { | |||
return saveProperty(change.id, change.info, 'transitions', {}); | |||
}; | |||
|
|||
const saveCompletedTasks = (id, infodoc) => { | |||
return saveProperty(id, infodoc, 'completed_tasks', {}); | |||
const saveCompletedTasks = (id, infodoc, completedTasks = []) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... now that I check the implementation, I see that the property value was taken from the infodoc that was already passed, my bad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
@@ -155,8 +155,8 @@ const saveTransitions = change => { | |||
return saveProperty(change.id, change.info, 'transitions', {}); | |||
}; | |||
|
|||
const saveCompletedTasks = (id, infodoc) => { | |||
return saveProperty(id, infodoc, 'completed_tasks', {}); | |||
const saveCompletedTasks = (id, infodoc, completedTasks = []) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... now that I check the implementation, I see that the property value was taken from the infodoc that was already passed, my bad!
Description
When two out bound pushes running against the same document (same doc id) there is an uncaught error as shown below while writing to the sentinel info doc that leads to duplication in the push.
while looping thru the outbound keys eg push-1 and push-2,
push-1 will successfully write the info doc for the report
when it get to push-2 it attempts to
put
the info doc but runs into a conflict errorThis will lead to creation of an unnecessary task:outbound which leads to push-2 being pushed again.
Fixes #9854
Code review checklist
can_view_old_navigation
permission to see the old design. Test it has appropriate design for RTL languages.License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.