diff --git a/eva-remapping-ingest/src/main/java/uk/ac/ebi/eva/remapping/ingest/batch/tasklets/StoreRemappingMetadataTasklet.java b/eva-remapping-ingest/src/main/java/uk/ac/ebi/eva/remapping/ingest/batch/tasklets/StoreRemappingMetadataTasklet.java index 53e98f248..80e6a7b4c 100644 --- a/eva-remapping-ingest/src/main/java/uk/ac/ebi/eva/remapping/ingest/batch/tasklets/StoreRemappingMetadataTasklet.java +++ b/eva-remapping-ingest/src/main/java/uk/ac/ebi/eva/remapping/ingest/batch/tasklets/StoreRemappingMetadataTasklet.java @@ -19,9 +19,9 @@ import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.dao.DuplicateKeyException; import org.springframework.data.mongodb.core.MongoTemplate; -import uk.ac.ebi.eva.remapping.ingest.parameters.InputParameters; public class StoreRemappingMetadataTasklet implements Tasklet { @@ -36,7 +36,12 @@ public StoreRemappingMetadataTasklet(MongoTemplate mongoTemplate, RemappingMetad @Override public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { - mongoTemplate.save(remappingMetadata, "remappingMetadata"); + try { + // Save will insert if not present + mongoTemplate.save(remappingMetadata, "remappingMetadata"); + } catch (DuplicateKeyException e) { + // Do nothing if already present (only in race condition) + } return RepeatStatus.FINISHED; } }