mirror of
https://github.com/sismics/docs.git
synced 2024-11-15 18:57:56 +01:00
handle index rebuilding
This commit is contained in:
parent
95ce4f0dc0
commit
b54debe2e5
@ -4,6 +4,7 @@ import com.google.common.eventbus.AsyncEventBus;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.sismics.docs.core.constant.Constants;
|
||||
import com.sismics.docs.core.dao.UserDao;
|
||||
import com.sismics.docs.core.event.RebuildIndexAsyncEvent;
|
||||
import com.sismics.docs.core.listener.async.*;
|
||||
import com.sismics.docs.core.model.jpa.User;
|
||||
import com.sismics.docs.core.service.InboxService;
|
||||
@ -11,6 +12,8 @@ import com.sismics.docs.core.util.PdfUtil;
|
||||
import com.sismics.docs.core.util.indexing.IndexingHandler;
|
||||
import com.sismics.docs.core.util.indexing.LuceneIndexingHandler;
|
||||
import com.sismics.util.EnvironmentUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -25,6 +28,11 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author jtremeaux
|
||||
*/
|
||||
public class AppContext {
|
||||
/**
|
||||
* Logger.
|
||||
*/
|
||||
private static final Logger log = LoggerFactory.getLogger(AppContext.class);
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*/
|
||||
@ -66,8 +74,9 @@ public class AppContext {
|
||||
try {
|
||||
indexingHandler.startUp();
|
||||
} catch (Exception e) {
|
||||
// Blocking error, the app will not start
|
||||
throw new RuntimeException(e);
|
||||
log.error("Error starting the indexing handler, rebuilding the index", e);
|
||||
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
||||
asyncEventBus.post(rebuildIndexAsyncEvent);
|
||||
}
|
||||
|
||||
// Start inbox service
|
||||
|
@ -7,8 +7,6 @@ import com.sismics.docs.core.constant.ConfigType;
|
||||
import com.sismics.docs.core.dao.ConfigDao;
|
||||
import com.sismics.docs.core.dao.criteria.DocumentCriteria;
|
||||
import com.sismics.docs.core.dao.dto.DocumentDto;
|
||||
import com.sismics.docs.core.event.RebuildIndexAsyncEvent;
|
||||
import com.sismics.docs.core.model.context.AppContext;
|
||||
import com.sismics.docs.core.model.jpa.Config;
|
||||
import com.sismics.docs.core.model.jpa.Document;
|
||||
import com.sismics.docs.core.model.jpa.File;
|
||||
@ -85,16 +83,11 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
||||
if (status.clean) {
|
||||
for (CheckIndex.Status.SegmentInfoStatus segmentInfo : status.segmentInfos) {
|
||||
if (!segmentInfo.version.onOrAfter(Version.LATEST)) {
|
||||
log.info("Index is old (" + segmentInfo.version + "), rebuilding");
|
||||
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
||||
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
|
||||
break;
|
||||
throw new Exception("Index is old (" + segmentInfo.version + ")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.info("Index is dirty, rebuilding");
|
||||
RebuildIndexAsyncEvent rebuildIndexAsyncEvent = new RebuildIndexAsyncEvent();
|
||||
AppContext.getInstance().getAsyncEventBus().post(rebuildIndexAsyncEvent);
|
||||
throw new Exception("Index is dirty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user