Skip to content

Commit

Permalink
Added: Exporter async execution pool
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Nov 14, 2024
1 parent eb83414 commit f9de297
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Catch token manager exceptions and return ERROR status
- Send emails in async execution pool
- Notification async execution pool
- Exporter async execution pool
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class ProjectManagerAsyncConfiguration {
private final int notificationCorePoolSize;
private final int notificationMaxPoolSize;
private final int notificationQueueCapacity;
private final int exporterCorePoolSize;
private final int exporterMaxPoolSize;
private final int exporterQueueCapacity;


public ProjectManagerAsyncConfiguration(
Expand All @@ -26,13 +29,19 @@ public ProjectManagerAsyncConfiguration(
@Value(ProjectManagerConst.EMAIL_SENDER_QUEUE_CAPACITY_SV) int emailSenderQueueCapacity,
@Value(ProjectManagerConst.NOTIFICATION_CORE_POOL_SIZE_SV) int notificationCorePoolSize,
@Value(ProjectManagerConst.NOTIFICATION_MAX_POOL_SIZE_SV) int notificationMaxPoolSize,
@Value(ProjectManagerConst.NOTIFICATION_QUEUE_CAPACITY_SV) int notificationQueueCapacity) {
@Value(ProjectManagerConst.NOTIFICATION_QUEUE_CAPACITY_SV) int notificationQueueCapacity,
@Value(ProjectManagerConst.EXPORTER_CORE_POOL_SIZE_SV) int exporterCorePoolSize,
@Value(ProjectManagerConst.EXPORTER_MAX_POOL_SIZE_SV) int exporterMaxPoolSize,
@Value(ProjectManagerConst.EXPORTER_QUEUE_CAPACITY_SV) int exporterQueueCapacity) {
this.emailSenderCorePoolSize = emailSenderCorePoolSize;
this.emailSenderMaxPoolSize = emailSenderMaxPoolSize;
this.emailSenderQueueCapacity = emailSenderQueueCapacity;
this.notificationCorePoolSize = notificationCorePoolSize;
this.notificationMaxPoolSize = notificationMaxPoolSize;
this.notificationQueueCapacity = notificationQueueCapacity;
this.exporterCorePoolSize = exporterCorePoolSize;
this.exporterMaxPoolSize = exporterMaxPoolSize;
this.exporterQueueCapacity = exporterQueueCapacity;
}

@Bean(name = ProjectManagerConst.ASYNC_EMAIL_SENDER_EXECUTOR)
Expand All @@ -47,6 +56,12 @@ public Executor notificationExecutor() {
notificationQueueCapacity, ProjectManagerConst.ASYNC_NOTIFICATION_EXECUTOR);
}

@Bean(name = ProjectManagerConst.ASYNC_EXPORTER_EXECUTOR)
public Executor exporterExecutor() {
return createEmailSenderExecutor(exporterCorePoolSize, exporterMaxPoolSize,
exporterQueueCapacity, ProjectManagerConst.ASYNC_EXPORTER_EXECUTOR);
}

private Executor createEmailSenderExecutor(int corePoolSize, int maxPoolSize, int queueCapacity, String prefix) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ public class ProjectManagerConst {
public final static String NOTIFICATION_MAX_POOL_SIZE = "NOTIFICATION_MAX_POOL_SIZE";
public final static String NOTIFICATION_QUEUE_CAPACITY = "NOTIFICATION_QUEUE_CAPACITY";

public final static String EXPORTER_CORE_POOL_SIZE = "EXPORTER_CORE_POOL_SIZE";
public final static String EXPORTER_MAX_POOL_SIZE = "EXPORTER_MAX_POOL_SIZE";
public final static String EXPORTER_QUEUE_CAPACITY = "EXPORTER_QUEUE_CAPACITY";

// Spring Values (SV)
public final static String HEAD_SV = "${";
public final static String BOTTOM_SV = "}";
Expand Down Expand Up @@ -467,9 +471,14 @@ public class ProjectManagerConst {
public final static String NOTIFICATION_MAX_POOL_SIZE_SV = HEAD_SV + NOTIFICATION_MAX_POOL_SIZE + ":8" + BOTTOM_SV;
public final static String NOTIFICATION_QUEUE_CAPACITY_SV = HEAD_SV + NOTIFICATION_QUEUE_CAPACITY + ":500" + BOTTOM_SV;

public final static String EXPORTER_CORE_POOL_SIZE_SV = HEAD_SV + EXPORTER_CORE_POOL_SIZE + ":4" + BOTTOM_SV;
public final static String EXPORTER_MAX_POOL_SIZE_SV = HEAD_SV + EXPORTER_MAX_POOL_SIZE + ":8" + BOTTOM_SV;
public final static String EXPORTER_QUEUE_CAPACITY_SV = HEAD_SV + EXPORTER_QUEUE_CAPACITY + ":500" + BOTTOM_SV;

// Async Configuration
public final static String ASYNC_EMAIL_SENDER_EXECUTOR = "email-sender";
public final static String ASYNC_NOTIFICATION_EXECUTOR = "notification";
public final static String ASYNC_EXPORTER_EXECUTOR = "exporter";

// Others
public final static String TEST_EMAIL = "[email protected]";
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/samply/exporter/ExporterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -122,6 +123,7 @@ public Mono<ExporterServiceResult> checkExecutionStatus(ProjectBridgehead projec
return postRequest(projectBridgehead, generateFocusBody(projectBridgehead, taskType), taskType);
}

@Async()
public void transferFileToResearchEnvironment(@NotNull String projectCode, @NotNull String bridgehead) {
Optional<ProjectCoder> projectCoder = this.projectCoderRepository.findByProjectBridgeheadUser_ProjectBridgehead_BridgeheadAndProjectBridgeheadUser_ProjectBridgehead_Project_CodeAndProjectBridgeheadUser_Email(bridgehead, projectCode, sessionUser.getEmail());
if (projectCoder.isEmpty()) {
Expand All @@ -138,6 +140,7 @@ public boolean isExportFileTransferredToResearchEnvironment(@NotNull String proj
return projectCoder.get().isExportTransferred();
}

@Async
public void transferFileToResearchEnvironment(ProjectCoder projectCoder) {
log.info("Transfering file to Coder for project " + projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getProject().getCode() + " in bridgehead " + projectCoder.getProjectBridgeheadUser().getProjectBridgehead().getBridgehead());
postRequest(projectCoder.getProjectBridgeheadUser().getProjectBridgehead(), generateTransferFileBeamRequest(projectCoder), TaskType.FILE_TRANSFER).subscribe(result -> {
Expand Down

0 comments on commit f9de297

Please sign in to comment.