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