All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tv.hd3g.jobkit.engine.JobTrait Maven / Gradle / Ivy

There is a newer version: 22.0.0
Show newest version
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);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy