Skip to content

Commit

Permalink
core: add WEEKEND policy, #TASK-6219
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Nov 12, 2024
1 parent 026635a commit 73b529a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class OperationExecutionConfig {
public enum Policy {
IMMEDIATE,
NIGHTLY,
WEEKLY,
NEVER
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -101,6 +103,11 @@ private void checkPendingVariantOperations(OperationChore operationChore)
return;
}

if (!isWeekend() && config.getPolicy() == OperationExecutionConfig.Policy.WEEKLY) {
logger.info("Waiting until weekend to check for pending operation '{}'", toolId);
return;
}

List<String> organizationIds = catalogManager.getOrganizationManager().getOrganizationIds(token);
QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, OrganizationDBAdaptor.QueryParams.PROJECTS.key());
for (String organizationId : organizationIds) {
Expand Down Expand Up @@ -360,6 +367,12 @@ private static boolean isNightTime() {
return isNightTime;
}

private static boolean isWeekend() {
LocalDate today = LocalDate.now();
DayOfWeek dayOfWeek = today.getDayOfWeek();
return dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY;
}

private boolean pendingJobs(String studyIds, String toolId) throws CatalogException {
return !noPendingJobs(Collections.singletonList(studyIds), Collections.singletonList(toolId));
}
Expand Down

0 comments on commit 73b529a

Please sign in to comment.