(→AHPSCRIPTS-91)
|
(→AHPSCRIPTS-59)
|
Line 194: | |||
==== AHPSCRIPTS-59 ==== | ==== AHPSCRIPTS-59 ==== | ||
<pre>return JobStatus.allAncestorsIn(new JobStatusEnum[] {JobStatusEnum.SUCCESS, JobStatusEnum.NOT_NEEDED})</pre> | <pre>return JobStatus.allAncestorsIn(new JobStatusEnum[] {JobStatusEnum.SUCCESS, JobStatusEnum.NOT_NEEDED})</pre> | ||
+ | = Run an Iterated Job if it is the First Job of Iteration or if Any of the Jobs in Workflow Failed = | ||
+ | *This script was used to satisfy a case where a customer wanted to run a job again if the initial run of the job failed. They accomplished this by iterating the job twice and using this pre-condition script which would run the job the first time and then only run the job on the second iteration if the first iteration failed. | ||
+ | ==== AHPSCRIPTS-97 ==== | ||
+ | <pre>import com.urbancode.anthill3.domain.workflow.WorkflowCase; | ||
+ | import org.apache.log4j.Logger; | ||
+ | Logger log = Logger.getLogger("script"); | ||
+ | return new Criteria() { | ||
+ | public boolean matches(Object obj) throws Exception { | ||
+ | boolean match = false; | ||
+ | WorkflowCase workflowCase = WorkflowLookup.getCurrentCase(); | ||
+ | JobTrace[] jobTraceArray = workflowCase.getJobTraceArray(); | ||
+ | if ("1".equals(PropertyLookup.get("anthill.job.iteration"))) { | ||
+ | log.warn("Running job because it is the first iteration."); | ||
+ | match = true; | ||
+ | } | ||
+ | else { | ||
+ | boolean anyJobsFailed = false; | ||
+ | for (int i = 0; i < jobTraceArray.length; ++i) { | ||
+ | if (JobStatusEnum.FAILED.equals(jobTraceArray[i].getStatus())) { | ||
+ | anyJobsFailed = true; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | if (anyJobsFailed){ | ||
+ | log.warn("Running job because the first job failed."); | ||
+ | match = true; | ||
+ | } else { | ||
+ | log.warn("Not running job. job count = " + | ||
+ | jobTraceArray.length + "."); | ||
+ | } | ||
+ | } | ||
+ | return match; | ||
+ | } | ||
+ | }</pre> |