Skip to content

Commit

Permalink
Planner #229: re-evaluate product queries of orders with execution ti…
Browse files Browse the repository at this point in the history
…me directly before start.
  • Loading branch information
emelchinger committed Jan 8, 2025
1 parent 57e9978 commit d974c81
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
Expand All @@ -27,9 +28,12 @@
import de.dlr.proseo.model.JobStep.StdLogLevel;
import de.dlr.proseo.model.Processor;
import de.dlr.proseo.model.Product;
import de.dlr.proseo.model.ProductQuery;
import de.dlr.proseo.model.Task;
import de.dlr.proseo.model.enums.JobOrderVersion;
import de.dlr.proseo.model.enums.OrderSource;
import de.dlr.proseo.model.joborder.JobOrder;
import de.dlr.proseo.model.service.ProductQueryService;
import de.dlr.proseo.model.service.RepositoryService;
import de.dlr.proseo.model.util.ProseoUtil;
import de.dlr.proseo.planner.ProductionPlanner;
Expand Down Expand Up @@ -64,7 +68,7 @@ public class KubeJob {

/** Logger of this class */
private static ProseoLogger logger = new ProseoLogger(KubeJob.class);

/** The job's database id */
private long jobId;

Expand Down Expand Up @@ -323,6 +327,10 @@ public KubeJob createJob(KubeConfig kubeConfig, String stdoutLogLevel, String st
if (logger.isTraceEnabled())
logger.trace(">>> execution time of order is after now.");
return null;
} else {
// reprocess the selection rules to get all "new" available input products
reexecuteProductQueries();

}
}

Expand Down Expand Up @@ -1359,4 +1367,32 @@ public String getJobStepLogPrim(V1Pod pod) {
}
}

private void reexecuteProductQueries() {

TransactionTemplate transactionTemplate = new TransactionTemplate(this.kubeConfig.getProductionPlanner().getTxManager());
transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);

transactionTemplate.setReadOnly(false);
transactionTemplate.execute(status -> {

// Find the job step in the database
Optional<JobStep> jobStepOptional = RepositoryService.getJobStepRepository().findById(this.getJobId());
if (jobStepOptional.isEmpty()) {
logger.log(PlannerMessage.JOB_STEP_NOT_FOUND, this.getJobId());
return null;
}
JobStep js = jobStepOptional.get();

// Iterate over the input product queries of the job step
for (ProductQuery productQuery : js.getInputProductQueries()) {
// Execute the product query always
ProductQueryService productQueryService = UtilService.getJobStepUtil().getProductQueryService();
if (productQueryService.executeQuery(productQuery, false)) {
// If the query is successfully executed, update its state and save
RepositoryService.getProductQueryRepository().save(productQuery);
}
}
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public class JobStepUtil {
@Autowired
RestTemplateBuilder rtb;

public ProductQueryService getProductQueryService() {
return productQueryService;
}
/**
* Retrieves job steps with a specific job step state, associated with a given mission code. Results are ordered by processing
* completion time in descending order, limited to a specified number.
Expand Down

0 comments on commit d974c81

Please sign in to comment.