fix #2365 add job name
This commit is contained in:
parent
30d19c4946
commit
7448b100f3
9 changed files with 63 additions and 24 deletions
|
@ -36,6 +36,16 @@ public class ScriptExecutorJob implements LaJob {
|
|||
|
||||
@Override
|
||||
public void run(final LaJobRuntime runtime) {
|
||||
final JobHelper jobHelper = ComponentUtil.getJobHelper();
|
||||
try {
|
||||
jobHelper.setJobRuntime(runtime);
|
||||
process(runtime);
|
||||
} finally {
|
||||
jobHelper.setJobRuntime(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void process(final LaJobRuntime runtime) {
|
||||
if (!runtime.getParameterMap().containsKey(Constants.SCHEDULED_JOB)) {
|
||||
logger.warn(Constants.SCHEDULED_JOB + " is empty.");
|
||||
return;
|
||||
|
|
|
@ -392,6 +392,7 @@ public class Crawler {
|
|||
|
||||
logger.debug("\ninfoMap: {}\ndataMap: {}", infoMap, dataMap);
|
||||
|
||||
final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
|
||||
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
|
||||
CrawlerPostcard.droppedInto(postbox, postcard -> {
|
||||
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
|
||||
|
@ -418,6 +419,7 @@ public class Crawler {
|
|||
} else {
|
||||
postcard.setStatus(Constants.FAIL);
|
||||
}
|
||||
postcard.setJobname(systemProperties.getProperty("job.runtime.name", StringUtil.EMPTY));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.codelibs.fess.util.ComponentUtil;
|
|||
import org.dbflute.optional.OptionalThing;
|
||||
import org.lastaflute.job.JobManager;
|
||||
import org.lastaflute.job.LaCron;
|
||||
import org.lastaflute.job.LaJobRuntime;
|
||||
import org.lastaflute.job.LaScheduledJob;
|
||||
import org.lastaflute.job.key.LaJobUnique;
|
||||
import org.lastaflute.job.subsidiary.CronParamsSupplier;
|
||||
|
@ -44,6 +45,8 @@ public class JobHelper {
|
|||
|
||||
protected int monitorInterval = 60 * 60;// 1hour
|
||||
|
||||
protected ThreadLocal<LaJobRuntime> jobRuntimeLocal = new ThreadLocal<>();
|
||||
|
||||
public void register(final ScheduledJob scheduledJob) {
|
||||
final JobManager jobManager = ComponentUtil.getJobManager();
|
||||
jobManager.schedule(cron -> register(cron, scheduledJob));
|
||||
|
@ -186,4 +189,11 @@ public class JobHelper {
|
|||
|
||||
}
|
||||
|
||||
public void setJobRuntime(LaJobRuntime runtime) {
|
||||
jobRuntimeLocal.set(runtime);
|
||||
}
|
||||
|
||||
public LaJobRuntime getJobRuntime() {
|
||||
return jobRuntimeLocal.get();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,10 @@ package org.codelibs.fess.job;
|
|||
import static org.codelibs.core.stream.StreamUtil.stream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -331,11 +329,7 @@ public class CrawlJob extends ExecJob {
|
|||
try {
|
||||
cmdList.add("-p");
|
||||
cmdList.add(propFile.getAbsolutePath());
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
prop.putAll(ComponentUtil.getSystemProperties());
|
||||
prop.store(out, cmdList.toString());
|
||||
}
|
||||
createSystemProperties(cmdList, propFile);
|
||||
|
||||
final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
|
||||
|
||||
|
|
|
@ -16,16 +16,23 @@
|
|||
package org.codelibs.fess.job;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.codelibs.core.timer.TimeoutManager;
|
||||
import org.codelibs.core.timer.TimeoutTask;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.es.config.exentity.ScheduledJob;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.di.exception.IORuntimeException;
|
||||
import org.lastaflute.job.LaJobRuntime;
|
||||
|
||||
public abstract class ExecJob {
|
||||
|
||||
|
@ -157,4 +164,22 @@ public abstract class ExecJob {
|
|||
processTimeout = true;
|
||||
}, timeout, false);
|
||||
}
|
||||
|
||||
protected void createSystemProperties(final List<String> cmdList, final File propFile) {
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
prop.putAll(ComponentUtil.getSystemProperties());
|
||||
final LaJobRuntime jobRuntime = ComponentUtil.getJobHelper().getJobRuntime();
|
||||
if (jobRuntime != null) {
|
||||
final ScheduledJob job = (ScheduledJob) jobRuntime.getParameterMap().get(Constants.SCHEDULED_JOB);
|
||||
if (job != null) {
|
||||
prop.setProperty("job.runtime.id", job.getId());
|
||||
prop.setProperty("job.runtime.name", job.getName());
|
||||
}
|
||||
}
|
||||
prop.store(out, cmdList.toString());
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,10 +18,8 @@ package org.codelibs.fess.job;
|
|||
import static org.codelibs.core.stream.StreamUtil.stream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
|
@ -212,11 +210,7 @@ public class GenerateThumbnailJob extends ExecJob {
|
|||
try {
|
||||
cmdList.add("-p");
|
||||
cmdList.add(propFile.getAbsolutePath());
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
prop.putAll(ComponentUtil.getSystemProperties());
|
||||
prop.store(out, cmdList.toString());
|
||||
}
|
||||
createSystemProperties(cmdList, propFile);
|
||||
|
||||
final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
|
||||
|
||||
|
|
|
@ -18,10 +18,8 @@ package org.codelibs.fess.job;
|
|||
import static org.codelibs.core.stream.StreamUtil.stream;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
|
@ -194,11 +192,7 @@ public class SuggestJob extends ExecJob {
|
|||
try {
|
||||
cmdList.add("-p");
|
||||
cmdList.add(propFile.getAbsolutePath());
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
prop.putAll(ComponentUtil.getSystemProperties());
|
||||
prop.store(out, cmdList.toString());
|
||||
}
|
||||
createSystemProperties(cmdList, propFile);
|
||||
|
||||
final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
|
||||
|
||||
|
|
|
@ -50,9 +50,9 @@ public class CrawlerPostcard extends LaTypicalPostcard {
|
|||
|
||||
@Override
|
||||
protected String[] getPropertyNames() {
|
||||
return new String[] { "hostname", "webFsCrawlStartTime", "webFsCrawlEndTime", "webFsCrawlExecTime", "webFsIndexExecTime",
|
||||
"webFsIndexSize", "dataCrawlStartTime", "dataCrawlEndTime", "dataCrawlExecTime", "dataIndexExecTime", "dataIndexSize",
|
||||
"crawlerStartTime", "crawlerEndTime", "crawlerExecTime", "status" };
|
||||
return new String[] { "hostname", "jobname", "webFsCrawlStartTime", "webFsCrawlEndTime", "webFsCrawlExecTime",
|
||||
"webFsIndexExecTime", "webFsIndexSize", "dataCrawlStartTime", "dataCrawlEndTime", "dataCrawlExecTime", "dataIndexExecTime",
|
||||
"dataIndexSize", "crawlerStartTime", "crawlerEndTime", "crawlerExecTime", "status" };
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
|
@ -109,6 +109,15 @@ public class CrawlerPostcard extends LaTypicalPostcard {
|
|||
registerVariable("hostname", hostname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of jobname, used in parameter comment. <br>
|
||||
* Even if empty string, treated as empty plainly. So "IF pmb != null" is false if empty.
|
||||
* @param jobname The parameter value of jobname. (NotNull)
|
||||
*/
|
||||
public void setJobname(String jobname) {
|
||||
registerVariable("jobname", jobname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of webFsCrawlStartTime, used in parameter comment. <br>
|
||||
* Even if empty string, treated as empty plainly. So "IF pmb != null" is false if empty.
|
||||
|
|
|
@ -6,6 +6,7 @@ subject: [FESS] Crawler completed: /*pmb.hostname*/
|
|||
>>>
|
||||
--- Server Info ---
|
||||
Host Name: /*pmb.hostname:orElse('Unknown')*/
|
||||
Job Name: /*pmb.jobname:orElse('Unknown')*/
|
||||
|
||||
--- Web/FileSystem Crawler ---
|
||||
Start Time: /*pmb.webFsCrawlStartTime:orElse('-')*/
|
||||
|
|
Loading…
Add table
Reference in a new issue