Skip to content

Commit

Permalink
Fix issue with re-running failed jobs via REST if child jobs had not …
Browse files Browse the repository at this point in the history
…yet been initiated/scheduled.
  • Loading branch information
mseaton committed Aug 3, 2023
1 parent c9158da commit 538f13e
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/main/java/org/pih/petl/web/JobExecutionRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,34 @@ private JobExecution executeIfIncomplete(JobExecution execution) {
JobConfig config = execution.getJobConfig();
execution.setStarted(new Date());
execution.setStatus(JobExecutionStatus.IN_PROGRESS);

// If this is a job pipeline or an iterating job that has already had it's child jobs scheduled,
// then just ensure that these child jobs are executed and successful, and mark parent as successful if so
if ("job-pipeline".equals(config.getType()) || "iterating-job".equals(config.getType())) {
boolean successful = true;
for (JobExecution childJobExecution : etlService.getChildExecutions(execution)) {
if (childJobExecution.getStatus() != JobExecutionStatus.SUCCEEDED) {
childJobExecution = executeIfIncomplete(childJobExecution);
successful = successful && childJobExecution.getStatus() == JobExecutionStatus.SUCCEEDED;
if ("job-pipeline".equals(config.getType()) && !successful) {
break;
List<JobExecution> existingChildExecutions = etlService.getChildExecutions(execution);
if (existingChildExecutions == null || existingChildExecutions.isEmpty()) {
execution = etlService.executeJob(execution);
}
else {
boolean successful = true;
for (JobExecution childJobExecution : etlService.getChildExecutions(execution)) {
if (childJobExecution.getStatus() != JobExecutionStatus.SUCCEEDED) {
childJobExecution = executeIfIncomplete(childJobExecution);
successful = successful && childJobExecution.getStatus() == JobExecutionStatus.SUCCEEDED;
if ("job-pipeline".equals(config.getType()) && !successful) {
break;
}
}
}
if (successful) {
execution.setStatus(JobExecutionStatus.SUCCEEDED);
execution.setErrorMessage(null);
} else {
execution.setStatus(JobExecutionStatus.FAILED);
}
execution.setCompleted(new Date());
execution = etlService.saveJobExecution(execution);
}
if (successful) {
execution.setStatus(JobExecutionStatus.SUCCEEDED);
execution.setErrorMessage(null);
} else {
execution.setStatus(JobExecutionStatus.FAILED);
}
execution.setCompleted(new Date());
execution = etlService.saveJobExecution(execution);
} else {
execution = etlService.executeJob(execution);
}
Expand Down

0 comments on commit 538f13e

Please sign in to comment.