Skip to content

Commit

Permalink
Added: Max time to wait focus task in minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Apr 18, 2024
1 parent d236ca8 commit f8cc582
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Send message while rejecting a project
- Exporter Job
- Check Queries in Exporter Job
- Max time to wait focus task in minutes
3 changes: 3 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public class ProjectManagerConst {
public final static String OIDC_URL = "OIDC_URL";
public final static String OIDC_REALM = "OIDC_REALM";
public final static String ENABLE_EXPORTER = "ENABLE_EXPORTER";
public final static String MAX_TIME_TO_WAIT_FOCUS_TASK_IN_MINUTES = "MAX_TIME_TO_WAIT_FOCUS_TASK_IN_MINUTES";

// Spring Values (SV)
public final static String HEAD_SV = "${";
Expand Down Expand Up @@ -345,6 +346,8 @@ public class ProjectManagerConst {
HEAD_SV + WEBCLIENT_TCP_KEEP_INTERVAL_IN_SECONDS + ":60" + BOTTOM_SV;
public final static String WEBCLIENT_TCP_KEEP_CONNECTION_NUMBER_OF_TRIES_SV =
HEAD_SV + WEBCLIENT_TCP_KEEP_CONNECTION_NUMBER_OF_TRIES + ":10" + BOTTOM_SV;
public final static String MAX_TIME_TO_WAIT_FOCUS_TASK_IN_MINUTES_SV =
HEAD_SV + MAX_TIME_TO_WAIT_FOCUS_TASK_IN_MINUTES + ":5" + BOTTOM_SV;
public final static String WEBCLIENT_MAX_NUMBER_OF_RETRIES_SV =
HEAD_SV + WEBCLIENT_MAX_NUMBER_OF_RETRIES + ":3" + BOTTOM_SV;
public final static String WEBCLIENT_TIME_IN_SECONDS_AFTER_RETRY_WITH_FAILURE_SV =
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/samply/exporter/ExporterJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Instant;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -78,6 +79,7 @@ private Mono<Void> checkQueries(QueryState initialQueryState, QueryState finalQu
ProjectBridgehead projectBridgehead = exporterServiceResult.projectBridgehead();
projectBridgehead.setQueryState(finalQueryState);
projectBridgehead.setExporterResponse(exporterServiceResult.result());
projectBridgehead.setModifiedAt(Instant.now());
projectBridgeheadRepository.save(projectBridgehead);
return Mono.empty();
}).then();
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/de/samply/exporter/ExporterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Expand All @@ -55,6 +56,7 @@ public class ExporterService {

private final String focusWaitTime;
private final String focusWaitCount;
private final int maxTimeToWaitFocusTaskInMinutes;
private ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT)
.registerModule(new JavaTimeModule()).configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

Expand All @@ -66,6 +68,7 @@ public ExporterService(
@Value(ProjectManagerConst.DATASHIELD_TEMPLATES_SV) Set<String> datashieldTemplates,
@Value(ProjectManagerConst.FOCUS_TTL_SV) String focusWaitTime,
@Value(ProjectManagerConst.FOCUS_FAILURE_STRATEGY_MAX_TRIES_SV) String focusWaitCount,
@Value(ProjectManagerConst.MAX_TIME_TO_WAIT_FOCUS_TASK_IN_MINUTES_SV) int maxTimeToWaitFocusTaskInMinutes,
FocusService focusService,
ProjectBridgeheadDataShieldRepository projectBridgeheadDataShieldRepository,
NotificationService notificationService,
Expand All @@ -79,6 +82,7 @@ public ExporterService(
this.focusProjectManagerId = focusProjectManagerId;
this.focusWaitTime = focusWaitTime;
this.focusWaitCount = focusWaitCount;
this.maxTimeToWaitFocusTaskInMinutes = maxTimeToWaitFocusTaskInMinutes;
this.webClient = webClientFactory.createWebClient(focusUrl);
this.focusApiKey = focusApiKey;
this.projectBridgeheadRepository = projectBridgeheadRepository;
Expand Down Expand Up @@ -237,7 +241,7 @@ public Mono<ExporterServiceResult> checkIfQueryIsAlreadySent(ProjectBridgehead p
} else {
log.error("Http Error " + clientResponse.statusCode() + " checking task " + projectBridgehead.getExporterResponse() +
" for project " + projectBridgehead.getProject().getCode() + " and bridgehead " + projectBridgehead.getBridgehead());
if (!clientResponse.statusCode().equals(HttpStatus.NO_CONTENT)) {
if (isQueryStateToBeChangedToError((HttpStatus) clientResponse.statusCode(), projectBridgehead)) {
projectBridgehead.setQueryState(QueryState.ERROR);
projectBridgehead.setModifiedAt(Instant.now());
projectBridgeheadRepository.save(projectBridgehead);
Expand All @@ -250,6 +254,13 @@ public Mono<ExporterServiceResult> checkIfQueryIsAlreadySent(ProjectBridgehead p
});
}

private boolean isQueryStateToBeChangedToError(HttpStatus httpStatus, ProjectBridgehead projectBridgehead) {
if (httpStatus == HttpStatus.NOT_FOUND) {
return Duration.between(projectBridgehead.getModifiedAt(), Instant.now()).toMinutes() > maxTimeToWaitFocusTaskInMinutes;
}
return httpStatus != HttpStatus.NO_CONTENT;
}

public Optional<String> fetchExporterExecutionIdFromExporterResponse(String exporterResponse) {
if (exporterResponse != null) {
Optional<FocusQuery[]> focusQuery = deserializeFocusResponse(exporterResponse);
Expand Down

0 comments on commit f8cc582

Please sign in to comment.