[New] Added StrolchJob loading of Manual, and new toString()

This commit is contained in:
Robert von Burg 2020-06-22 17:26:01 +02:00
parent 8bfd267c75
commit fe6d61a687
3 changed files with 37 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package li.strolch.job;
import static li.strolch.model.Tags.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.isEmpty;
import java.time.ZoneId;
import java.time.ZonedDateTime;
@ -267,8 +268,9 @@ public abstract class StrolchJob implements Runnable, Restrictable {
operationsLog.addMessage(
new LogMessage(this.realmName == null ? StrolchConstants.DEFAULT_REALM : this.realmName,
SYSTEM_USER_AGENT, Locator.valueOf(AGENT, "strolch-agent", StrolchAgent.getUniqueId()),
LogSeverity.Exception, LogMessageState.Information, ResourceBundle.getBundle("strolch-agent"), "strolchjob.failed")
.withException(e).value("jobName", getClass().getName()).value("reason", e));
LogSeverity.Exception, LogMessageState.Information,
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;
}
@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;
}
}

View File

@ -67,29 +67,31 @@ public class StrolchJobsHandler extends StrolchComponent {
tx.streamResources(TYPE_STROLCH_JOB).forEach(jobRes -> {
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());
StrolchJob job = instantiateJob(className, jobRes.getId(), jobRes.getName(), mode);
job.setConfigureMethod(ConfigureMethod.Model).setMode(mode);
if (jobRes.hasParameter(PARAM_CRON)) {
String cron = jobRes.getParameter(PARAM_CRON, true).getValue();
job.setCronExpression(cron, startDateP.toZonedDateTime());
} else if (jobRes.hasParameter(PARAM_INITIAL_DELAY) && jobRes.hasParameter(PARAM_DELAY)) {
IntegerParameter initialDelayP = jobRes.getParameter(PARAM_INITIAL_DELAY, true);
IntegerParameter delayP = jobRes.getParameter(PARAM_DELAY, true);
TimeUnit initialDelayUnit = TimeUnit.valueOf(initialDelayP.getUom());
TimeUnit delayUnit = TimeUnit.valueOf(delayP.getUom());
job.setDelay(initialDelayP.getValue(), initialDelayUnit, delayP.getValue(), delayUnit);
} else {
logger.error("Job " + jobRes.getId()
+ " is inconsistent, as either cron, or initialDelay/delay is missing!");
return;
if (mode != JobMode.Manual) {
if (jobRes.hasParameter(PARAM_CRON)) {
String cron = jobRes.getParameter(PARAM_CRON, true).getValue();
DateParameter startDateP = jobRes.getParameter(PARAM_START_DATE, true);
job.setCronExpression(cron, startDateP.toZonedDateTime());
} else if (jobRes.hasParameter(PARAM_INITIAL_DELAY) && jobRes.hasParameter(PARAM_DELAY)) {
IntegerParameter initialDelayP = jobRes.getParameter(PARAM_INITIAL_DELAY, true);
IntegerParameter delayP = jobRes.getParameter(PARAM_DELAY, true);
TimeUnit initialDelayUnit = TimeUnit.valueOf(initialDelayP.getUom());
TimeUnit delayUnit = TimeUnit.valueOf(delayP.getUom());
job.setDelay(initialDelayP.getValue(), initialDelayUnit, delayP.getValue(), delayUnit);
} else {
logger.error("Job " + jobRes.getId()
+ " is inconsistent, as either cron, or initialDelay/delay is missing!");
return;
}
}
jobs.add(job);
logger.info("Added job " + job.getName() + ": " + job.getCron() + " from model.");
logger.info("Added job " + job + " from model.");
});
}
}

View File

@ -69,6 +69,8 @@ public class StrolchModelConstants {
public static final String TYPE_ENUMERATION = "Enumeration";
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
*/