handle duplicate notifications sent for the same book from different tasks - #515
handle duplicate notifications sent for the same book from different tasks#515elfkuzco wants to merge 2 commits into
Conversation
6b0d5ea to
48f0a22
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #515 +/- ##
==========================================
- Coverage 81.78% 81.75% -0.03%
==========================================
Files 69 69
Lines 4397 4412 +15
Branches 515 518 +3
==========================================
+ Hits 3596 3607 +11
- Misses 640 642 +2
- Partials 161 163 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| zimfarm_notification.events.append( | ||
| f"{getnow()}: notification transformed into book" | ||
| ) | ||
|
|
There was a problem hiding this comment.
Why changing this ordering, I don't get the difference?
There was a problem hiding this comment.
During tests for processing duplicate notifications, I found out the notification gets updated even though book might possibly fail to be added to the DB.
There was a problem hiding this comment.
This is weird ... please better understand where, all this is supposed to run in a single transaction
| f"{getnow()}: created from Zimfarm notification {zimfarm_notification.id}" | ||
| ) | ||
|
|
||
| session.flush() |
There was a problem hiding this comment.
I don't feel like session.flush is strictly mandatory, I feel like it is more something needed for tests only (and could reduce perf on prod). Could you explain or move to test?
There was a problem hiding this comment.
It helps propagate/detect the Integrity early error early from where it was introduced. If we remove it, the next time it would get thrown would be from the call to update a title upload or getting an existing task because in SQLAlcheny, select and update calls automatically trigger flush. I figured there'd be no difference and it might as well happen explicitly. Plus, I can infer correctly which function threw the error
| f"{getnow()}: added {status} location: {filename} in {warehouse_name}: " | ||
| f"{path} ({warehouse_id})" | ||
| ) | ||
| session.flush() |
There was a problem hiding this comment.
I don't feel like session.flush is strictly mandatory, I feel like it is more something needed for tests only (and could reduce perf on prod). Could you explain or move to test?
There was a problem hiding this comment.
It happens automatically during future calls to get matching title or any other queries involving select which will definitely happen during notification processing timeline. Happening during automatically invoked calls makes it harder to know and catch the block that introduced it
| zimcheck_result_url=zimcheck_url, | ||
| zimfarm_notification=notification, | ||
| ) | ||
| except IntegrityError: |
There was a problem hiding this comment.
This is very fragile in the sense that we could have other integrity errors in the future. Why not simply checking that a book with same ID does not already exists before trying to create it?
There was a problem hiding this comment.
This is very fragile in the sense that we could have other integrity errors in the future. Why not simply checking that a book with same ID does not already exists before trying to create it?
That works too.
| # If zimfarm notification came because of a title upload mark it as failed | ||
| if get_title_upload_or_none(session, notification.task_id) is not None: | ||
| update_title_upload_status(session, notification.task_id, "failed") | ||
| notification.status = "bad_notification" |
There was a problem hiding this comment.
shall we use duplicate_book_id as status? I feel like it is way more explicit and will make things more understandable for the end user
| ) | ||
| # If zimfarm notification came because of a title upload mark it as failed | ||
| if get_title_upload_or_none(session, notification.task_id) is not None: | ||
| update_title_upload_status(session, notification.task_id, "failed") |
There was a problem hiding this comment.
Shall we use another status than "failed" like "duplicate_upload" to make things clearer for the end user. We should also update UI to add a small text explaining this issue (like a question mark button next to this status when shown which opens a popup explaining what happened).

Changes
This fixes #494