Skip to content

Commit

Permalink
Move demographic recache to post commit task (#781)
Browse files Browse the repository at this point in the history
* Make demographic recache a post commit task
* Remove delay from job as recache is now running after the transaction commits
* Add some test helpers
  • Loading branch information
labkey-martyp authored May 9, 2024
1 parent 4130353 commit d43576e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private void asyncCache(final Container c, final List<String> ids)
{
_log.error("EHRDemographicsServiceImpl encountered a deadlock", e);
}
}, 5000);
});
}

/**
Expand Down
13 changes: 12 additions & 1 deletion ehr/src/org/labkey/ehr/utils/TriggerScriptHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.labkey.api.data.ContainerManager;
import org.labkey.api.data.ConvertHelper;
import org.labkey.api.data.DbSchema;
import org.labkey.api.data.DbScope;
import org.labkey.api.data.Results;
import org.labkey.api.data.ResultsImpl;
import org.labkey.api.data.RuntimeSQLException;
Expand Down Expand Up @@ -871,7 +872,17 @@ public void createDemographicsRecord(String id, Map<String, Object> props,
// inserted a row into study.participant, which means that calculated lookup values like the animal's current
// age won't resolve until AFTER the call to insertRows() has completed. Thus, refresh the cache for this new
// animal an extra time. See ticket 44283.
EHRDemographicsServiceImpl.get().recacheRecords(getContainer(), Collections.singletonList(id));
try (DbScope.Transaction transaction = StudyService.get().getDatasetSchema().getScope().ensureTransaction())
{
// Add post commit task to run provider update in another thread once this transaction is complete.
transaction.addCommitTask(() ->
{
// Update provider in another thread
EHRDemographicsServiceImpl.get().recacheRecords(getContainer(), Collections.singletonList(id));
}, DbScope.CommitTaskOption.POSTCOMMIT);

transaction.commit();
}
}

public void updateDemographicsRecord(List<Map<String, Object>> updatedRows) throws QueryUpdateServiceException, SQLException, BatchValidationException, InvalidKeyException
Expand Down
8 changes: 8 additions & 0 deletions ehr/test/src/org/labkey/test/tests/ehr/AbstractEHRTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ protected void createTestSubjects() throws Exception
insertCommand = getApiHelper().prepareInsertCommand("study", "Assignment", "lsid", fields, data);
getApiHelper().deleteAllRecords("study", "Assignment", new Filter("Id", StringUtils.join(SUBJECTS, ";"), Filter.Operator.IN));
getApiHelper().doSaveRows(DATA_ADMIN.getEmail(), insertCommand, getExtraContext());

primeCaches();
}

@Override
Expand Down Expand Up @@ -756,6 +758,12 @@ private void setEhrUserPasswords()
setInitialPassword(REQUEST_ADMIN.getEmail());
}

protected void validateDemographicsCache()
{
beginAt(WebTestHelper.buildURL("ehr", getContainerPath(), "cacheLivingAnimals", Map.of("validateOnly", "true")));
waitAndClick(WAIT_FOR_JAVASCRIPT, Locator.lkButton("OK"), WAIT_FOR_PAGE * 4);
}

protected static final ArrayList<Permission> allowedActions = new ArrayList<>()
{
{
Expand Down
21 changes: 21 additions & 0 deletions ehr/test/src/org/labkey/test/util/ehr/EHRTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
import org.labkey.test.Locators;
import org.labkey.test.components.ext4.Window;
import org.labkey.test.pages.ehr.ParticipantViewPage;
import org.labkey.test.tests.ehr.AbstractEHRTest;
import org.labkey.test.util.Ext4Helper;
Expand Down Expand Up @@ -246,6 +247,26 @@ public void discardForm()
_test.waitForElement(Locator.tagWithText("a", "Enter New Data"));
}

public void submitFinalTaskForm()
{
Locator submitFinalBtn = Locator.linkWithText("Submit Final");
_test.shortWait().until(ExpectedConditions.elementToBeClickable(submitFinalBtn));
Window<?> msgWindow;
try
{
submitFinalBtn.findElement(_test.getDriver()).click();
msgWindow = new Window.WindowFinder(_test.getDriver()).withTitleContaining("Finalize").waitFor();
}
catch (NoSuchElementException e)
{
//retry
_test.sleep(500);
submitFinalBtn.findElement(_test.getDriver()).click();
msgWindow = new Window.WindowFinder(_test.getDriver()).withTitleContaining("Finalize").waitFor();
}
msgWindow.clickButton("Yes");
}

public void verifyAllReportTabs(ParticipantViewPage participantView)
{
verifyReportTabs(participantView, Collections.emptyMap());
Expand Down

0 comments on commit d43576e

Please sign in to comment.