mirror of https://github.com/halo-dev/halo
chore: update the waiting time for publishing post (#4814)
#### What type of PR is this? /kind improvement /area core /milestone 2.11.x #### What this PR does / why we need it: 修改发布文章的等待时间以防止因数据库执行延迟较高导致的错误提示 最大等待时间为:`100ms * 2 ^ (retryNum - 1)` = `25600ms` 总共需等待时间为:`100ms * (2 ^ retryNum - 1)` = `31900ms` = `31.9 s` #### Does this PR introduce a user-facing change? ```release-note None ```pull/4819/head
parent
57b24261e7
commit
b8755ff3b4
|
@ -8,7 +8,7 @@ import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuil
|
|||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springdoc.core.fn.builders.schema.Builder;
|
||||
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder;
|
||||
|
@ -42,9 +42,10 @@ import run.halo.app.extension.router.QueryParamBuildUtil;
|
|||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class PostEndpoint implements CustomEndpoint {
|
||||
|
||||
private int maxAttemptsWaitForPublish = 10;
|
||||
private final PostService postService;
|
||||
private final ReactiveExtensionClient client;
|
||||
|
||||
|
@ -243,7 +244,7 @@ public class PostEndpoint implements CustomEndpoint {
|
|||
})
|
||||
.switchIfEmpty(Mono.error(
|
||||
() -> new RetryException("Retry to check post publish status"))))
|
||||
.retryWhen(Retry.backoff(5, Duration.ofMillis(100))
|
||||
.retryWhen(Retry.backoff(maxAttemptsWaitForPublish, Duration.ofMillis(100))
|
||||
.filter(t -> t instanceof RetryException));
|
||||
}
|
||||
|
||||
|
@ -278,4 +279,11 @@ public class PostEndpoint implements CustomEndpoint {
|
|||
return postService.listPost(postQuery)
|
||||
.flatMap(listedPosts -> ServerResponse.ok().bodyValue(listedPosts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient for testing, to avoid waiting too long for post published when testing.
|
||||
*/
|
||||
public void setMaxAttemptsWaitForPublish(int maxAttempts) {
|
||||
this.maxAttemptsWaitForPublish = maxAttempts;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ class PostEndpointTest {
|
|||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
postEndpoint.setMaxAttemptsWaitForPublish(3);
|
||||
webTestClient = WebTestClient
|
||||
.bindToRouterFunction(postEndpoint.endpoint())
|
||||
.build();
|
||||
|
@ -170,7 +171,7 @@ class PostEndpointTest {
|
|||
.is5xxServerError();
|
||||
|
||||
// Verify WebClient retry behavior
|
||||
verify(client, times(7)).get(eq(Post.class), eq("post-1"));
|
||||
verify(client, times(5)).get(eq(Post.class), eq("post-1"));
|
||||
verify(client).update(any(Post.class));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue