Skip to content

Commit

Permalink
refactor: ensure each subscription happens on a dedicated single-thre…
Browse files Browse the repository at this point in the history
…aded worker for mono callable
  • Loading branch information
guqing committed May 26, 2023
1 parent a32d3d3 commit 4a97dd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private Mono<ServerResponse> upgradeFromUri(ServerRequest request) {
.flatMap(upgradeRequest -> Mono.fromCallable(() -> DataBufferUtils.toInputStream(
reactiveUrlDataBufferFetcher.fetch(upgradeRequest.uri())))
)
.subscribeOn(Schedulers.boundedElastic())
.onErrorMap(throwable -> {
log.error("Failed to fetch plugin file from uri.", throwable);
return new ThemeUpgradeException("Failed to fetch plugin file from uri.", null,
Expand All @@ -247,6 +248,7 @@ private Mono<ServerResponse> installFromUri(ServerRequest request) {
.flatMap(installRequest -> Mono.fromCallable(() -> DataBufferUtils.toInputStream(
reactiveUrlDataBufferFetcher.fetch(installRequest.uri())))
)
.subscribeOn(Schedulers.boundedElastic())
.doOnError(throwable -> {
log.error("Failed to fetch plugin file from uri.", throwable);
throw new ThemeInstallationException("Failed to fetch plugin file from uri.", null,
Expand Down Expand Up @@ -605,6 +607,6 @@ private Mono<Path> transferToTemp(InputStream inputStream) {
Path tempFile = Files.createTempFile("halo-plugins", ".jar");
FileCopyUtils.copy(inputStream, Files.newOutputStream(tempFile));
return tempFile;
});
}).subscribeOn(Schedulers.boundedElastic());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.web.server.ServerWebInputException;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.util.retry.Retry;
import run.halo.app.core.extension.Setting;
import run.halo.app.core.extension.Theme;
Expand Down Expand Up @@ -247,6 +248,7 @@ private Mono<ServerResponse> upgradeFromUri(ServerRequest request) {
.flatMap(upgradeRequest -> Mono.fromCallable(() -> DataBufferUtils.toInputStream(
reactiveUrlDataBufferFetcher.fetch(upgradeRequest.uri())))
)
.subscribeOn(Schedulers.boundedElastic())
.doOnError(throwable -> {
log.error("Failed to fetch zip file from uri.", throwable);
throw new ThemeUpgradeException("Failed to fetch zip file from uri.", null,
Expand All @@ -268,6 +270,7 @@ private Mono<ServerResponse> installFromUri(ServerRequest request) {
.flatMap(installRequest -> Mono.fromCallable(() -> DataBufferUtils.toInputStream(
reactiveUrlDataBufferFetcher.fetch(installRequest.uri())))
)
.subscribeOn(Schedulers.boundedElastic())
.doOnError(throwable -> {
log.error("Failed to fetch zip file from uri.", throwable);
throw new ThemeInstallationException("Failed to fetch zip file from uri.", null,
Expand Down

0 comments on commit 4a97dd6

Please sign in to comment.