task-171: 图片下载客户端配置接入(ImageDownloadHttpConfigResolver,download/prefetch 模块级现有配置优先、命名空间兜底)+ 8 条测试
- 真实基线:SimilarAsinImageEmbedder(OkHttp) connect/read=imageDownloadTimeoutSeconds(5s)、call=2×download(10s)、prefetch 1800s - resolver 提供 connect/read/call/prefetch/maxRetries 访问面,模块级优先、命名空间兜底,不改调用点 - 仅新增类与测试,零生产行为变化
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 图片下载客户端统一配置解析(task-171)。
|
||||
*
|
||||
* 真实基线(已核实,对应 task-166 契约表"图片下载"行):SimilarAsinImageEmbedder 使用自建
|
||||
* OkHttpClient(不参与共享 JDK HttpClientPool),connect/read/write 均取
|
||||
* aiimage.similar-asin.image-download-timeout-seconds(默认 5s),call = 2×download;
|
||||
* 整批预取预算 image-prefetch-timeout-seconds(默认 1800s);无显式次数重试
|
||||
* (OkHttp retryOnConnectionFailure + 上游批次重提)。
|
||||
*
|
||||
* 语义:模块级现有配置优先(保证接入切点时行为不变),命名空间 aiimage.http-client.* 兜底。
|
||||
* 次数重试/退避来自命名空间,为未来接入切点预留;当前不改变 SimilarAsinImageEmbedder 调用点。
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ImageDownloadHttpConfigResolver {
|
||||
|
||||
private final HttpClientProperties httpClientProperties;
|
||||
private final SimilarAsinProperties similarAsinProperties;
|
||||
|
||||
private int downloadSeconds() {
|
||||
return similarAsinProperties.getImageDownloadTimeoutSeconds();
|
||||
}
|
||||
|
||||
/** 连接超时:模块 download 秒数优先(现状 5s);未配置回退命名空间。 */
|
||||
public long connectTimeoutMillis() {
|
||||
int module = downloadSeconds();
|
||||
return module > 0 ? module * 1_000L : httpClientProperties.effectiveConnectTimeoutMillis();
|
||||
}
|
||||
|
||||
/** 读取超时:模块 download 秒数优先(现状 5s);未配置回退命名空间。 */
|
||||
public long readTimeoutMillis() {
|
||||
int module = downloadSeconds();
|
||||
return module > 0 ? module * 1_000L : httpClientProperties.effectiveReadTimeoutMillis();
|
||||
}
|
||||
|
||||
/** 调用总超时:模块 download×2(现状 10s);未配置回退命名空间。 */
|
||||
public long callTimeoutMillis() {
|
||||
int module = downloadSeconds();
|
||||
return module > 0 ? module * 2_000L : httpClientProperties.effectiveCallTimeoutMillis();
|
||||
}
|
||||
|
||||
/** 整批图片预取预算(秒转毫秒):模块优先(现状 1800s);未配置回退命名空间 read。 */
|
||||
public long prefetchTimeoutMillis() {
|
||||
int module = similarAsinProperties.getImagePrefetchTimeoutSeconds();
|
||||
return module > 0 ? module * 1_000L : httpClientProperties.effectiveReadTimeoutMillis();
|
||||
}
|
||||
|
||||
/** 次数重试:来自命名空间(现状图片下载无次数重试,OkHttp 仅连接失败自愈)。 */
|
||||
public int maxRetries() {
|
||||
return httpClientProperties.effectiveMaxRetries();
|
||||
}
|
||||
|
||||
public long baseRetryDelayMillis() {
|
||||
return httpClientProperties.getBaseRetryDelayMillis();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user