fix #1461 handle unexpected exceptions
This commit is contained in:
parent
b48273fda9
commit
881beb0110
2 changed files with 34 additions and 3 deletions
|
@ -17,13 +17,21 @@ package org.codelibs.fess.es.config.exbhv;
|
|||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.codelibs.fess.es.config.bsbhv.BsScheduledJobBhv;
|
||||
import org.codelibs.fess.es.config.exentity.ScheduledJob;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author FreeGen
|
||||
*/
|
||||
public class ScheduledJobBhv extends BsScheduledJobBhv {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ScheduledJobBhv.class);
|
||||
|
||||
private String indexName = null;
|
||||
|
||||
@Override
|
||||
|
@ -34,4 +42,26 @@ public class ScheduledJobBhv extends BsScheduledJobBhv {
|
|||
}
|
||||
return indexName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalEntity<ScheduledJob> selectByPK(final String id) {
|
||||
Exception lastException = null;
|
||||
for (int i = 0; i < 30; i++) {
|
||||
try {
|
||||
return super.selectByPK(id);
|
||||
} catch (Exception e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to select a job by " + id, e);
|
||||
}
|
||||
lastException = e;
|
||||
try {
|
||||
Thread.sleep(RandomUtils.nextLong(500, 5000));
|
||||
} catch (InterruptedException e1) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.warn("Failed to select a job by " + id, lastException);
|
||||
return OptionalEntity.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.codelibs.fess.es.config.exbhv.JobLogBhv;
|
|||
import org.codelibs.fess.es.config.exbhv.ScheduledJobBhv;
|
||||
import org.codelibs.fess.es.config.exentity.JobLog;
|
||||
import org.codelibs.fess.es.config.exentity.ScheduledJob;
|
||||
import org.codelibs.fess.exception.JobNotFoundException;
|
||||
import org.codelibs.fess.job.ScheduledJobException;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
|
@ -71,8 +70,10 @@ public class JobHelper {
|
|||
final CronParamsSupplier paramsOp =
|
||||
() -> {
|
||||
final Map<String, Object> params = new HashMap<>();
|
||||
params.put(Constants.SCHEDULED_JOB, ComponentUtil.getComponent(ScheduledJobBhv.class).selectByPK(scheduledJob.getId())
|
||||
.orElseThrow(() -> new JobNotFoundException(scheduledJob)));
|
||||
ComponentUtil.getComponent(ScheduledJobBhv.class).selectByPK(scheduledJob.getId())
|
||||
.ifPresent(e -> params.put(Constants.SCHEDULED_JOB, e)).orElse(() -> {
|
||||
logger.warn("Job " + scheduledJob.getId() + " is not found.");
|
||||
});
|
||||
return params;
|
||||
};
|
||||
findJobByUniqueOf(LaJobUnique.of(id)).ifPresent(job -> {
|
||||
|
|
Loading…
Add table
Reference in a new issue