OBPIH-6864 Fix assign identifier job#4967
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4967 +/- ##
============================================
- Coverage 7.61% 7.61% -0.01%
Complexity 817 817
============================================
Files 601 601
Lines 42300 42302 +2
Branches 10277 10276 -1
============================================
Hits 3222 3222
- Misses 38610 38612 +2
Partials 468 468 ☔ View full report in Codecov by Sentry. |
|
Currently this is throwing the following errors whenever the job is run: Still need to figure out why |
| import org.pih.warehouse.requisition.RequisitionIdentifierService | ||
| import org.pih.warehouse.shipping.ShipmentIdentifierService | ||
|
|
||
| @Transactional |
There was a problem hiding this comment.
I had to add this to make the job work. Without the @transactional it was hitting "no transaction is in progress" errors.
Maybe a better solution is to wrap each individual generateForAllUnassignedIdentifiers() call in their own transaction based on the underlying table that they're working on.
Or perhaps even better, simply put the @transactional on the XIdentiferService classes themselves and remove it from here so that if there's a failure in one, it doesn't affect the others.
@awalkowiak I see you had this PR relating to transactions in jobs so maybe you'll know better than me #4160
There was a problem hiding this comment.
Possibly relevant since we are doing sessionRequired=false in all our jobs: https://grails.github.io/grails-quartz/guide/configuration.html
Hibernate Sessions and Jobs
Jobs are configured by default to have Hibernate Session bounded to thread each time job is executed. This is required if you are using Hibernate code which requires open session (such as lazy loading of collections) or working with domain objects with unique persistent constraint (it uses Hibernate Session behind the scene). If you want to override this behavior (rarely useful) you can use 'sessionRequired' property:def sessionRequired = false
There was a problem hiding this comment.
Thinking about it for a bit, I'd like to just put @transactional on all the XIdentiferService classes since that's what makes sense to me (they should probably be transactional anyways).
There was a problem hiding this comment.
@ewaterman here you might find a bit more details about the issue with no transaction is in progress https://pihemr.atlassian.net/browse/OBGM-584 (this is the OG ticket under which I introduced the wrapping service calls with the withNewSession), this was basically the same issue you run into here: #4967 (comment), back then I remember @Transactional did not work for me. Does the @Transactional work now? Are the new identifiers persisted to the db correctly now?
| // TODO: investigate why this merge with flush and no validation is required. Can we simplify this to | ||
| // a regular save operation? | ||
| if (!entity.merge(flush: true, validate: false)) { | ||
| if (!entity.save()) { |
There was a problem hiding this comment.
from what I've gathered, the merge was required because the assign identifier job was wrapping all the generate id calls with the same Product.withNewSession, even though only one of them was actually saving to product. This meant that the entities might not have been in the session, and so we were forced to work with detached objects via merge. Now that we're leaving the transactions to the individual services themselves, which do the work to fetch the entities (and thus load them into the session) this is no longer required.
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-6864
Description: The AssignIdentifierJob wasn't running properly because it was unable to auto-wire in the BlankIdentifierResolver beans. This should work according to Springboot, but it's not worth the hassle trying to debug why it's not working here so I just switched it to wire in the BlankIdentifierResolver classes explicitly.
📷 Screenshots & Recordings (optional)