Skip to content

Instantly share code, notes, and snippets.

@happz
Created December 10, 2013 10:45
Show Gist options
  • Save happz/7888757 to your computer and use it in GitHub Desktop.
Save happz/7888757 to your computer and use it in GitHub Desktop.
JobIsRunning - Matcher[] support
public class JobIsRunning implements WaitCondition {
private Logger log = Logger.getLogger(JobIsRunning.class);
private Matcher[] includeJobs;
private Matcher[] excludeJobs;
public JobIsRunning() {
this(null, null);
}
public JobIsRunning(Matcher[] excludeJobs) {
this(null, excludeJobs);
}
public JobIsRunning(Matcher[] includeJobs, Matcher[] excludeJobs) {
this.includeJobs = includeJobs;
this.excludeJobs = excludeJobs;
}
@Override
public boolean test() {
log.debug("test:");
for (Job job: Job.getJobManager().find(null)) {
/* use includeJobs to force waiting for system jobs, sleeping jobs or jobs that
* are skipped for any other reason */
if (includeJobs != null && CoreMatchers.anyOf(includeJobs).matches(job.getName())) {
log.debug(" job '%s' specified by includeJobs matchers, wait for it", job.getName());
return true;
}
/* skip system jobs or jobs that are sleeping */
if (job.isSystem() || job.getState() == Job.SLEEPING) {
log.debug(" job '%s' is system job or not running, skipped", job.getName());
continue;
}
/* skip jobs that user wants to ignore */
if (excludeJobs != null && CoreMatchers.anyOf(excludeJobs).matches(job.getName())) {
log.debug(" job '%s' specified by excludeJobs matchers, skipped", job.getName());
continue;
}
/* ok, no reason why this one should be ignored, lets wait... */
log.debug(" job '%s' has no excuses, wait for it", job.getName());
return true;
}
return false;
}
@Override
public String description() {
return "At least one job is running.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment