add scheduler name

This commit is contained in:
Shinsuke Sugaya 2015-12-29 22:08:47 +09:00
parent fbd076fec8
commit 72e8b4df0e
4 changed files with 52 additions and 7 deletions

View file

@ -15,6 +15,7 @@
*/
package org.codelibs.fess.es.config.exentity;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.es.config.bsentity.BsJobLog;
import org.codelibs.fess.util.ComponentUtil;
@ -36,9 +37,10 @@ public class JobLog extends BsJobLog {
setJobName(scheduledJob.getName());
setScriptType(scheduledJob.getScriptType());
setScriptData(scheduledJob.getScriptData());
setTarget(scheduledJob.getTarget());
setStartTime(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
setJobStatus(Constants.RUNNING);
final String myName = ComponentUtil.getFessConfig().getSchedulerTargetName();
setTarget(StringUtil.isNotBlank(myName) ? myName : Constants.DEFAULT_JOB_TARGET);
}
public ScheduledJob getScheduledJob() {

View file

@ -20,17 +20,16 @@ import static org.quartz.JobBuilder.newJob;
import static org.quartz.JobKey.jobKey;
import static org.quartz.TriggerBuilder.newTrigger;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.Constants;
import org.codelibs.fess.es.config.exbhv.JobLogBhv;
import org.codelibs.fess.es.config.exbhv.ScheduledJobBhv;
import org.codelibs.fess.es.config.exentity.ScheduledJob;
import org.codelibs.fess.helper.JobHelper;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.quartz.Job;
import org.quartz.JobDataMap;
@ -52,8 +51,6 @@ public class JobScheduler {
public Class<? extends Job> jobClass = TriggeredJob.class;
public List<String> targetList = new ArrayList<String>();
@PostConstruct
public void init() {
final SchedulerFactory sf = new StdSchedulerFactory();
@ -69,6 +66,15 @@ public class JobScheduler {
cb.query().addOrderBy_SortOrder_Asc();
cb.query().addOrderBy_Name_Asc();
}, scheduledJob -> register(scheduledJob));
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String myName = fessConfig.getSchedulerTargetName();
if (StringUtil.isNotBlank(myName)) {
ComponentUtil.getComponent(JobLogBhv.class).queryDelete(cb -> {
cb.query().setJobStatus_Equal(Constants.RUNNING);
cb.query().setTarget_Equal(myName);
});
}
}
@PreDestroy
@ -148,10 +154,15 @@ public class JobScheduler {
return true;
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String myName = fessConfig.getSchedulerTargetName();
final String[] targets = target.split(",");
for (String name : targets) {
name = name.trim();
if (Constants.DEFAULT_JOB_TARGET.equals(name) || targetList.contains(name)) {
if (Constants.DEFAULT_JOB_TARGET.equalsIgnoreCase(name)) {
return true;
} else if (StringUtil.isNotBlank(myName) && myName.equalsIgnoreCase(name)) {
return true;
}
}

View file

@ -309,6 +309,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. root@localhost */
String MAIL_FROM_ADDRESS = "mail.from.address";
/** The key of the configuration. e.g. */
String SCHEDULER_TARGET_NAME = "scheduler.target.name";
/** The key of the configuration. e.g. http://fess.codelibs.org/{lang}/{version}/admin/ */
String ONLINE_HELP_BASE_LINK = "online.help.base.link";
@ -1411,6 +1414,23 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
String getMailFromAddress();
/**
* Get the value for the key 'scheduler.target.name'. <br>
* The value is, e.g. <br>
* comment: ------
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getSchedulerTargetName();
/**
* Get the value for the key 'scheduler.target.name' as {@link Integer}. <br>
* The value is, e.g. <br>
* comment: ------
* @return The value of found property. (NotNull: if not found, exception but basically no way)
* @throws NumberFormatException When the property is not integer.
*/
Integer getSchedulerTargetNameAsInteger();
/**
* Get the value for the key 'online.help.base.link'. <br>
* The value is, e.g. http://fess.codelibs.org/{lang}/{version}/admin/ <br>
@ -2298,6 +2318,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return get(FessConfig.MAIL_FROM_ADDRESS);
}
public String getSchedulerTargetName() {
return get(FessConfig.SCHEDULER_TARGET_NAME);
}
public Integer getSchedulerTargetNameAsInteger() {
return getAsInteger(FessConfig.SCHEDULER_TARGET_NAME);
}
public String getOnlineHelpBaseLink() {
return get(FessConfig.ONLINE_HELP_BASE_LINK);
}

View file

@ -187,6 +187,10 @@ paging.search.page.max.size=100
mail.from.name = Administrator
mail.from.address = root@localhost
# ----------------------------------------------------------
# Scheduler
# ------
scheduler.target.name=
# ----------------------------------------------------------
# OnlineHelp