19 package org.turro.scheduler.task;
21 import org.turro.scheduler.task.settings.TaskSettings;
22 import java.time.Duration;
23 import java.util.Date;
24 import java.util.concurrent.ScheduledFuture;
25 import org.turro.elephant.context.IConstructor;
26 import org.turro.html.Colors;
27 import org.turro.log.WebLoggers;
28 import org.turro.scheduler.motor.Motor;
29 import org.turro.string.Phrases;
30 import org.turro.util.Comparison;
36 public abstract class AbstractTask implements Runnable, Comparable<AbstractTask> {
38 private ScheduledFuture<?> future;
43 private Date lastExecuted;
46 this.constructor = constructor;
50 this.settings = settings;
63 this.lastExecuted = lastExecuted;
67 return future ==
null ? true : future.isDone();
71 if(enoughTimeLapse(now) && settings.
shouldRun(now)) {
78 lastExecuted =
new Date();
83 if(future !=
null && !future.isDone()) {
92 }
catch(Exception ex) {
102 private boolean enoughTimeLapse(Date now) {
103 return lastExecuted ==
null || (Duration.between(lastExecuted.toInstant(), now.toInstant()).getSeconds() > (60 * 5));
109 return Colors.cssByName(
isSystem() ?
"DarkRed" :
"DarkBlue");
113 return isSystem() ?
"gears" :
"user";
117 return Phrases.start()
127 return Comparison.ascendant()
static WebLoggers warning(Object entity)
WebLoggers exception(Throwable throwable)
ScheduledFuture<?> runTask(AbstractTask task)
abstract String getDataLabel()
TaskSettings getSettings()
boolean shouldRun(Date now)
void setConstructor(IConstructor constructor)
IConstructor getConstructor()
void setLastExecuted(Date lastExecuted)
abstract boolean isSystem()
int compareTo(AbstractTask o)
void setSettings(TaskSettings settings)
abstract String getName()
static TaskSettings from(AbstractTask task)
TaskConstraints getConstraints()
boolean shouldRun(Date now)