tv.hd3g.jobkit.engine.JobTrait Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jobkit-engine Show documentation
Show all versions of jobkit-engine Show documentation
Execute onetime and scheduled jobs with dynamic queues and events
package tv.hd3g.jobkit.engine;
import java.util.function.Consumer;
public interface JobTrait {
/**
* @return true if the task is queued
*/
boolean runOneShot(final String name,
final String spoolName,
final int priority,
final RunnableWithException task,
final Consumer afterRunCommand);
/**
* @return true if the task is queued
*/
default boolean runOneShot(final Job job) {
final RunnableWithException run = () -> {
job.onJobStart();
job.run();
};
final Consumer afterRunCommand = e -> {
if (e != null) {
job.onJobFail(e);
} else {
job.onJobDone();
}
};
return runOneShot(job.getJobName(), job.getJobSpoolname(), job.getJobPriority(), run, afterRunCommand);
}
}