[New] Added StrolchJob loading of Manual, and new toString()
This commit is contained in:
parent
8bfd267c75
commit
fe6d61a687
|
@ -3,6 +3,7 @@ package li.strolch.job;
|
||||||
import static li.strolch.model.Tags.AGENT;
|
import static li.strolch.model.Tags.AGENT;
|
||||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||||
import static li.strolch.utils.helper.StringHelper.formatMillisecondsDuration;
|
import static li.strolch.utils.helper.StringHelper.formatMillisecondsDuration;
|
||||||
|
import static li.strolch.utils.helper.StringHelper.isEmpty;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
@ -267,8 +268,9 @@ public abstract class StrolchJob implements Runnable, Restrictable {
|
||||||
operationsLog.addMessage(
|
operationsLog.addMessage(
|
||||||
new LogMessage(this.realmName == null ? StrolchConstants.DEFAULT_REALM : this.realmName,
|
new LogMessage(this.realmName == null ? StrolchConstants.DEFAULT_REALM : this.realmName,
|
||||||
SYSTEM_USER_AGENT, Locator.valueOf(AGENT, "strolch-agent", StrolchAgent.getUniqueId()),
|
SYSTEM_USER_AGENT, Locator.valueOf(AGENT, "strolch-agent", StrolchAgent.getUniqueId()),
|
||||||
LogSeverity.Exception, LogMessageState.Information, ResourceBundle.getBundle("strolch-agent"), "strolchjob.failed")
|
LogSeverity.Exception, LogMessageState.Information,
|
||||||
.withException(e).value("jobName", getClass().getName()).value("reason", e));
|
ResourceBundle.getBundle("strolch-agent"), "strolchjob.failed").withException(e)
|
||||||
|
.value("jobName", getClass().getName()).value("reason", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,4 +448,18 @@ public abstract class StrolchJob implements Runnable, Restrictable {
|
||||||
|
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String schedule;
|
||||||
|
if (this.mode == JobMode.Manual)
|
||||||
|
schedule = this.mode.name();
|
||||||
|
else if (isEmpty(this.cron))
|
||||||
|
schedule = this.mode.name() + " Delay: " + this.initialDelay + " " + this.initialDelayTimeUnit + ", "
|
||||||
|
+ this.delay + " " + this.delayTimeUnit;
|
||||||
|
else
|
||||||
|
schedule = this.mode.name() + " " + this.cron;
|
||||||
|
|
||||||
|
return "Job " + this.id + " / " + this.name + " @ " + schedule;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,29 +67,31 @@ public class StrolchJobsHandler extends StrolchComponent {
|
||||||
tx.streamResources(TYPE_STROLCH_JOB).forEach(jobRes -> {
|
tx.streamResources(TYPE_STROLCH_JOB).forEach(jobRes -> {
|
||||||
|
|
||||||
String className = jobRes.getParameter(PARAM_CLASS_NAME, true).getValue();
|
String className = jobRes.getParameter(PARAM_CLASS_NAME, true).getValue();
|
||||||
DateParameter startDateP = jobRes.getParameter(PARAM_START_DATE, true);
|
|
||||||
JobMode mode = JobMode.valueOf(jobRes.getParameter(PARAM_MODE, true).getValue());
|
JobMode mode = JobMode.valueOf(jobRes.getParameter(PARAM_MODE, true).getValue());
|
||||||
|
|
||||||
StrolchJob job = instantiateJob(className, jobRes.getId(), jobRes.getName(), mode);
|
StrolchJob job = instantiateJob(className, jobRes.getId(), jobRes.getName(), mode);
|
||||||
job.setConfigureMethod(ConfigureMethod.Model).setMode(mode);
|
job.setConfigureMethod(ConfigureMethod.Model).setMode(mode);
|
||||||
|
|
||||||
if (jobRes.hasParameter(PARAM_CRON)) {
|
if (mode != JobMode.Manual) {
|
||||||
String cron = jobRes.getParameter(PARAM_CRON, true).getValue();
|
if (jobRes.hasParameter(PARAM_CRON)) {
|
||||||
job.setCronExpression(cron, startDateP.toZonedDateTime());
|
String cron = jobRes.getParameter(PARAM_CRON, true).getValue();
|
||||||
} else if (jobRes.hasParameter(PARAM_INITIAL_DELAY) && jobRes.hasParameter(PARAM_DELAY)) {
|
DateParameter startDateP = jobRes.getParameter(PARAM_START_DATE, true);
|
||||||
IntegerParameter initialDelayP = jobRes.getParameter(PARAM_INITIAL_DELAY, true);
|
job.setCronExpression(cron, startDateP.toZonedDateTime());
|
||||||
IntegerParameter delayP = jobRes.getParameter(PARAM_DELAY, true);
|
} else if (jobRes.hasParameter(PARAM_INITIAL_DELAY) && jobRes.hasParameter(PARAM_DELAY)) {
|
||||||
TimeUnit initialDelayUnit = TimeUnit.valueOf(initialDelayP.getUom());
|
IntegerParameter initialDelayP = jobRes.getParameter(PARAM_INITIAL_DELAY, true);
|
||||||
TimeUnit delayUnit = TimeUnit.valueOf(delayP.getUom());
|
IntegerParameter delayP = jobRes.getParameter(PARAM_DELAY, true);
|
||||||
job.setDelay(initialDelayP.getValue(), initialDelayUnit, delayP.getValue(), delayUnit);
|
TimeUnit initialDelayUnit = TimeUnit.valueOf(initialDelayP.getUom());
|
||||||
} else {
|
TimeUnit delayUnit = TimeUnit.valueOf(delayP.getUom());
|
||||||
logger.error("Job " + jobRes.getId()
|
job.setDelay(initialDelayP.getValue(), initialDelayUnit, delayP.getValue(), delayUnit);
|
||||||
+ " is inconsistent, as either cron, or initialDelay/delay is missing!");
|
} else {
|
||||||
return;
|
logger.error("Job " + jobRes.getId()
|
||||||
|
+ " is inconsistent, as either cron, or initialDelay/delay is missing!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jobs.add(job);
|
jobs.add(job);
|
||||||
logger.info("Added job " + job.getName() + ": " + job.getCron() + " from model.");
|
logger.info("Added job " + job + " from model.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ public class StrolchModelConstants {
|
||||||
public static final String TYPE_ENUMERATION = "Enumeration";
|
public static final String TYPE_ENUMERATION = "Enumeration";
|
||||||
public static final String TYPE_CONFIGURATION = "Configuration";
|
public static final String TYPE_CONFIGURATION = "Configuration";
|
||||||
|
|
||||||
|
public static final String RES_CONFIGURATION = "configuration";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID of the admin role which has access to all resources
|
* ID of the admin role which has access to all resources
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue