Now you cannot run tasks second time or if requirements are not met

This commit is contained in:
Евгений Смирнов 2021-07-10 20:19:57 +03:00
parent 7f57510ac8
commit 953614a7d8

View File

@ -17,6 +17,7 @@
*/
package ru.windcorp.progressia.common.modules;
import ru.windcorp.jputil.chars.StringUtil;
import ru.windcorp.progressia.common.util.crash.CrashReports;
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
@ -43,10 +44,26 @@ public abstract class Task
@Override
public void run() {
if (!canRun()) {
ArrayList<Task> undoneTasks = new ArrayList<>();
for (Task j : requiredTasks) {
if (!j.isDone()) {
undoneTasks.add(j);
}
}
throw CrashReports.report(new Throwable(),
"The following required Tasks are not done:\n%s",
StringUtil.iterableToString(undoneTasks, "\n"));
} else if (isDone()) {
throw CrashReports.report(new Throwable(),
"The task cannot be performed second time");
} else {
isActive = true;
perform();
isDone = true;
}
}
//This method will be invoked by Run()
protected abstract void perform();