Commit 88594865 authored by Matija Obreza's avatar Matija Obreza

Scheduler uses CALLER_RUNS policy

Catch multiple accessions for 1 alias exception
parent d709287c
......@@ -36,6 +36,6 @@ public interface AccessionAliasRepository extends JpaRepository<AccessionAlias,
@Query("delete from AccessionAlias aa where aa.accession in (from Accession a where a.id in ( :ids ))")
void deleteForAccessions(@Param("ids") Collection<Long> accessionIds);
@Query("select aa.accession from AccessionAlias aa where aa.usedBy=?1 and aa.name=?2 and aa.aliasType=?3 and aa.accession.institute.code=?1")
@Query("select distinct aa.accession from AccessionAlias aa where aa.usedBy=?1 and aa.name=?2 and aa.aliasType=?3 and aa.accession.institute.code=?1")
Accession findAccession(String instCode, String name, int aliasType);
}
......@@ -92,6 +92,7 @@ import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TraitService;
import org.genesys2.spring.SecurityContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
......@@ -224,26 +225,31 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
if (accn != null) {
result.add(accn);
} else {
Accession accnByAlias = accessionAliasRepository.findAccession(aid3.getHoldingInstitute(), aid3.getAccessionName(),
AccessionAlias.AliasType.OTHERNUMB.getId());
if (accnByAlias != null) {
LOG.info("Found accession by alias " + accnByAlias);
// Genus must match
if (StringUtils.equalsIgnoreCase(aid3.getGenus(), accnByAlias.getTaxonomy().getGenus()))
result.add(accnByAlias);
else {
LOG.info("... but genus doesn't match");
try {
Accession accnByAlias = accessionAliasRepository.findAccession(aid3.getHoldingInstitute(), aid3.getAccessionName(),
AccessionAlias.AliasType.OTHERNUMB.getId());
if (accnByAlias != null) {
LOG.info("Found accession by alias " + accnByAlias);
// Genus must match
if (StringUtils.equalsIgnoreCase(aid3.getGenus(), accnByAlias.getTaxonomy().getGenus()))
result.add(accnByAlias);
else {
LOG.info("... but genus doesn't match");
result.add(null);
}
} else {
result.add(null);
if (LOG.isDebugEnabled()) {
// Only log full miss
LOG.debug("No accession " + aid3);
}
}
} else {
} catch (IncorrectResultSizeDataAccessException e) {
LOG.warn("Multple accessions with alias " + aid3);
result.add(null);
if (LOG.isDebugEnabled()) {
// Only log full miss
LOG.debug("No accession " + aid3);
}
}
}
}
......
......@@ -16,8 +16,11 @@
package org.genesys2.spring.config;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
......@@ -27,11 +30,14 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
public class SpringSchedulerConfig {
@Bean
public ThreadPoolTaskExecutor taskExecutor() {
@Bean(destroyMethod = "shutdown")
public TaskExecutor taskExecutor() {
final ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
pool.setCorePoolSize(5);
pool.setMaxPoolSize(16);
pool.setCorePoolSize(4);
pool.setMaxPoolSize(8);
pool.setQueueCapacity(10);
pool.setThreadNamePrefix("genesys-background-");
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
return pool;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment