Skip to content

Commit

Permalink
use scheduler framework
Browse files Browse the repository at this point in the history
  • Loading branch information
blueSwordfish committed May 13, 2024
1 parent dbfb98e commit 5aa7673
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import gsrs.module.substance.standardizer.NameStandardizerConfiguration;
import gsrs.module.substance.standardizer.StructureStandardizerConfiguration;
import gsrs.module.substance.standardizer.SubstanceSynchronizer;
import gsrs.module.substance.tasks.DatabaseIndexSyncTask;
import gsrs.module.substance.utils.MolWeightCalculatorProperties;
import gsrs.module.substance.utils.SubstanceMatchViewGenerator;
import gsrs.module.substance.utils.SubstanceResultListRecordGenerator;
Expand Down Expand Up @@ -52,7 +51,6 @@
ConsoleFilterService.class,
BulkSearchService.class,
UserSavedListService.class,
DatabaseIndexSyncTask.class,
SubstanceMatchViewGenerator.class,
SubstanceResultListRecordGenerator.class,
SubstanceSequenceFileSupportService.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;

import gsrs.controller.AbstractLegacyTextSearchGsrsEntityController;
import gsrs.controller.hateoas.GsrsEntityToControllerMapper;
import gsrs.scheduledTasks.ScheduledTaskInitializer;
import gsrs.scheduledTasks.SchedulerPlugin;
import gsrs.springUtils.StaticContextAccessor;
import ix.utils.Util;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@ConditionalOnProperty(name = "entity.database.index.sync.scheduler.enabled", havingValue = "true")
public class DatabaseIndexSyncTask {

@Value("${database.index.sync.scheduler.entities:}")
private String entityString;
public class DatabaseIndexSyncTaskInitializer extends ScheduledTaskInitializer{

private String entityString;

@JsonProperty("entityString")
public void setEntityString(String entities) {
this.entityString = entities;
}


private final Set<String> supportedEntities = Util.toSet("Code","ControlledVocabulary","Name", "Reference","Substance");

@Scheduled(cron= "${database.index.sync.scheduler.cron}")
public void runSyncTask() {


@Override
public void run(SchedulerPlugin.JobStats stats, SchedulerPlugin.TaskListener l) {
if(entityString.length()==0) {
log.info("No entities defined for the database and index sync scheduler.");
return;
Expand Down Expand Up @@ -85,4 +84,10 @@ public void runSyncTask() {
private String generateEntityClassName(String entity) {
return "ix.ginas.models.v1." + entity;
}

@Override
public String getDescription() {
return "Reindex entities in backup tables that are not in indexes";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ eureka.client.enabled= false
ix.index.deepfields = ["ix.ginas.models.v1.Substance"]
ix.index.deepfieldsraw = "ix.ginas.models.v1.Substance"

entity.database.index.sync.scheduler.enabled=false
database.index.sync.scheduler.entities="Substance,Code"
database.index.sync.scheduler.cron="0 * * * * ?"


# When an unspecified search happens, promote all
# exact matches that match specific fields over
# the rest of the matches. In other words,
Expand Down Expand Up @@ -554,6 +549,13 @@ gsrs.entityProcessors=[


gsrs.scheduled-tasks.list=[
{
"scheduledTaskClass" : "gsrs.module.substance.tasks.DatabaseIndexSyncTaskInitializer",
"parameters" : {
"autorun": false,
"entityString" : "Code,ControlledVocabulary,Name,Reference,Substance"
}
},
{
"scheduledTaskClass" : "gsrs.module.substance.tasks.ReindexTaskInitializer",
"parameters" : {
Expand Down

0 comments on commit 5aa7673

Please sign in to comment.