Skip to content

OBPIH-6864 Fix assign identifier job#4967

Merged
awalkowiak merged 4 commits intodevelopfrom
bug/OBPIH-6864-assign-identifier-job-not-running
Dec 5, 2024
Merged

OBPIH-6864 Fix assign identifier job#4967
awalkowiak merged 4 commits intodevelopfrom
bug/OBPIH-6864-assign-identifier-job-not-running

Conversation

@ewaterman
Copy link
Member

✨ Description of Change

A concise summary of what is being changed. Please provide enough context for reviewers to be able to understand the change and why it is necessary. If the issue/ticket already provides enough information, you can put "See ticket" as the description.

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)

If this PR contains a UI change, consider adding one or more screenshots here or link to a screen recording to help reviewers visualize the change. Otherwise, you can remove this section.

Screenshot from 2024-12-02 10-26-31

@ewaterman ewaterman self-assigned this Dec 2, 2024
@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: backend Changes or discussions relating to the backend server labels Dec 2, 2024
@codecov
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 7.61%. Comparing base (7057b93) to head (c55a359).
Report is 104 commits behind head on develop.

Files with missing lines Patch % Lines
.../org/pih/warehouse/jobs/AssignIdentifierJob.groovy 0.00% 6 Missing ⚠️
...core/identification/BlankIdentifierResolver.groovy 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@ewaterman
Copy link
Member Author

ewaterman commented Dec 2, 2024

Currently this is throwing the following errors whenever the job is run:

Exception occurred in job: Grails Job
org.quartz.JobExecutionException: javax.persistence.TransactionRequiredException: no transaction is in progress
        at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111)
        at org.quartz.Job$execute.call(Unknown Source)
        at grails.plugins.quartz.QuartzDisplayJob.execute(QuartzDisplayJob.groovy:34)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
        at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3505)
        ....

Still need to figure out why

import org.pih.warehouse.requisition.RequisitionIdentifierService
import org.pih.warehouse.shipping.ShipmentIdentifierService

@Transactional
Copy link
Member Author

@ewaterman ewaterman Dec 2, 2024

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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).

Copy link
Collaborator

Choose a reason for hiding this comment

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

@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()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@awalkowiak awalkowiak merged commit c6b8d10 into develop Dec 5, 2024
@awalkowiak awalkowiak deleted the bug/OBPIH-6864-assign-identifier-job-not-running branch December 5, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants