From ff2bba3999d8c9aaa06a9ea7490d4685e74172e2 Mon Sep 17 00:00:00 2001 From: volodymyr Date: Wed, 6 Nov 2024 23:12:07 -0700 Subject: [PATCH] Bulk Import job status not changed after activation - failing test, fix, changelog --- ...lk-import-job-status-not-changing-after-activation.yaml | 6 ++++++ .../uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportSvcImpl.java | 7 +++++++ .../uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6451-bulk-import-job-status-not-changing-after-activation.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6451-bulk-import-job-status-not-changing-after-activation.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6451-bulk-import-job-status-not-changing-after-activation.yaml new file mode 100644 index 000000000000..ce62822d3707 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_6_0/6451-bulk-import-job-status-not-changing-after-activation.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 6451 +jira: SMILE-9089 +title: "Previously, activating `BulkDataImport` job would not change jobs status to `RUNNING`, +causing it to be processed multiple times instead of single time. This has been fixed." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportSvcImpl.java index 42eba8257550..bf72dbf645ce 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportSvcImpl.java @@ -217,6 +217,12 @@ private ActivateJobResult doActivateNextReadyJob() { String biJobId = null; try { biJobId = processJob(bulkImportJobEntity); + // set job status to RUNNING so it would not be processed again + myTxTemplate.execute(t -> { + bulkImportJobEntity.setStatus(BulkImportJobStatusEnum.RUNNING); + myJobDao.save(bulkImportJobEntity); + return null; + }); } catch (Exception e) { ourLog.error("Failure while preparing bulk export extract", e); myTxTemplate.execute(t -> { @@ -256,6 +262,7 @@ public BulkImportJobJson fetchJob(String theBiJobId) { } @Override + @Transactional public JobInfo getJobStatus(String theBiJobId) { BulkImportJobEntity theJob = findJobByBiJobId(theBiJobId); return new JobInfo() diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java index dec666c0c157..7c3a6e67c46e 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java @@ -17,6 +17,7 @@ import ca.uhn.fhir.jpa.bulk.imprt.model.ActivateJobResult; import ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobFileJson; import ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobJson; +import ca.uhn.fhir.jpa.bulk.imprt.model.BulkImportJobStatusEnum; import ca.uhn.fhir.jpa.bulk.imprt.model.JobFileRowProcessingModeEnum; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.subscription.channel.api.ChannelConsumerSettings; @@ -166,6 +167,8 @@ public void testFlow_TransactionRows() { ActivateJobResult activateJobOutcome = mySvc.activateNextReadyJob(); assertTrue(activateJobOutcome.isActivated); + // validate that job changed status from READY to RUNNING + assertEquals(BulkImportJobStatusEnum.RUNNING, mySvc.getJobStatus(jobId).getStatus()); JobInstance instance = myBatch2JobHelper.awaitJobCompletion(activateJobOutcome.jobId, 60); assertNotNull(instance); @@ -196,6 +199,8 @@ public void testFlow_WithTenantNamesInInput() { ActivateJobResult activateJobOutcome = mySvc.activateNextReadyJob(); assertTrue(activateJobOutcome.isActivated); + // validate that job changed status from READY to RUNNING + assertEquals(BulkImportJobStatusEnum.RUNNING, mySvc.getJobStatus(jobId).getStatus()); JobInstance instance = myBatch2JobHelper.awaitJobCompletion(activateJobOutcome.jobId); assertNotNull(instance);