Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait until job finishes #348

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.stream.Stream;

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

import gsrs.controller.AbstractLegacyTextSearchGsrsEntityController;
import gsrs.controller.hateoas.GsrsEntityToControllerMapper;
Expand Down Expand Up @@ -42,11 +41,13 @@ public void run(SchedulerPlugin.JobStats stats, SchedulerPlugin.TaskListener l)
log.info("DatabaseIndexSyncTask: No allowed entities defined for the database and index sync scheduler.");
return;
}

l.message("Getting entities synchronized");
for(String entity: syncEntities) {

String entityClassName = generateEntityClassName(entity);
log.info("DatabaseIndexSyncTask: Entity class: " + entityClassName);
//To improve: need a generalized way of dealing with this, there are several different versions of this
//need to do this in a utility class

l.message("Start indexing " + entity);
String entityClassName = generateEntityClassName(entity);

if(entityClassName.isEmpty()) {
log.error("Illegal entity class: " + entity + " in database and index sync scheduler.");
Expand All @@ -69,25 +70,38 @@ public void run(SchedulerPlugin.JobStats stats, SchedulerPlugin.TaskListener l)
if(!controllerOpt.isPresent()) {
continue;
}

AbstractLegacyTextSearchGsrsEntityController searchController = (AbstractLegacyTextSearchGsrsEntityController) StaticContextAccessor.getBean(controllerOpt.get());
try {
searchController.syncIndexesWithDatabase();
} catch (JsonProcessingException e) {
log.error("Error in database and index sync scheduler: " + entityClassName);

log.info("Starting DatabaseIndexSync job for Entity class: " + entity);

AbstractLegacyTextSearchGsrsEntityController.ReindexJobStatus stat = searchController.syncIndexesWithDatabaseWithStatus();

while(!stat.isDone()) {
l.message(entity + ": " + stat.getStatus());
stat = searchController.getJobStatus(stat.getStatusID());
Thread.sleep(2000);
}
l.message("Indexing " + entity + " is done");

log.info("Ending DatabaseIndexSync job for Entity class: " + entity);

} catch (Exception e) {
log.error("Error in database and index sync scheduler: " + entity);
e.printStackTrace();
continue;
}
}
}

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";
return "Database and index sync: reindex entities in backup tables that are not in indexes";
}

}