Forráskód Böngészése

add scheduler name

Shinsuke Sugaya 9 éve
szülő
commit
72e8b4df0e

+ 3 - 1
src/main/java/org/codelibs/fess/es/config/exentity/JobLog.java

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

+ 17 - 6
src/main/java/org/codelibs/fess/job/JobScheduler.java

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

+ 28 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -309,6 +309,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. root@localhost */
     /** The key of the configuration. e.g. root@localhost */
     String MAIL_FROM_ADDRESS = "mail.from.address";
     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/ */
     /** The key of the configuration. e.g. http://fess.codelibs.org/{lang}/{version}/admin/ */
     String ONLINE_HELP_BASE_LINK = "online.help.base.link";
     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();
     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>
      * Get the value for the key 'online.help.base.link'. <br>
      * The value is, e.g. http://fess.codelibs.org/{lang}/{version}/admin/ <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);
             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() {
         public String getOnlineHelpBaseLink() {
             return get(FessConfig.ONLINE_HELP_BASE_LINK);
             return get(FessConfig.ONLINE_HELP_BASE_LINK);
         }
         }

+ 4 - 0
src/main/resources/fess_config.properties

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