Skip to content

Commit

Permalink
Merge pull request #460 from apriltuesday/EVA-3595
Browse files Browse the repository at this point in the history
EVA-3595: Catch DuplicateKeyException for remapping metadata
  • Loading branch information
apriltuesday authored Sep 20, 2024
2 parents 57a91fb + c5ad70f commit 719d7d7
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
}

0 comments on commit 719d7d7

Please sign in to comment.