完善重试日志
查询历史录像
This commit is contained in:
parent
b7b70fe42f
commit
62cd5e2016
@ -58,20 +58,20 @@ public class WvpService {
|
|||||||
public final static int DEFAULT_RETRY_WAIT_TIME = 3;
|
public final static int DEFAULT_RETRY_WAIT_TIME = 3;
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
private static RetryListener defaultRetryListener() {
|
private static RetryListener defaultRetryListener(String name) {
|
||||||
return new RetryListener() {
|
return new RetryListener() {
|
||||||
@Override
|
@Override
|
||||||
public <V> void onRetry(Attempt<V> attempt) {
|
public <V> void onRetry(Attempt<V> attempt) {
|
||||||
log.info("第 {} 次 执行结束", attempt.getAttemptNumber());
|
log.info("第 {} 次 执行 {} 结束", attempt.getAttemptNumber(), name);
|
||||||
if (attempt.hasException()) {
|
if (attempt.hasException()) {
|
||||||
log.info("异常 {}", attempt.getExceptionCause().getMessage());
|
log.info("执行 {} 异常 {}", name, attempt.getExceptionCause().getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
private static <T> Retryer<JsonResponse<T>> getDefaultRetryer() {
|
private static <T> Retryer<JsonResponse<T>> getDefaultRetryer(String name) {
|
||||||
return RetryerBuilder.<JsonResponse<T>>newBuilder()
|
return RetryerBuilder.<JsonResponse<T>>newBuilder()
|
||||||
// 异常就重试
|
// 异常就重试
|
||||||
.retryIfException()
|
.retryIfException()
|
||||||
@ -81,12 +81,12 @@ public class WvpService {
|
|||||||
// 重试次数
|
// 重试次数
|
||||||
.withStopStrategy(StopStrategies.stopAfterAttempt(DEFAULT_RETRY_TIME))
|
.withStopStrategy(StopStrategies.stopAfterAttempt(DEFAULT_RETRY_TIME))
|
||||||
.retryIfResult(result -> result != null && (result.getCode() != 0 || result.getCode() != 200))
|
.retryIfResult(result -> result != null && (result.getCode() != 0 || result.getCode() != 200))
|
||||||
.withRetryListener(defaultRetryListener())
|
.withRetryListener(defaultRetryListener(name))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
private static Retryer<JsonResponse<?>> getDefaultGenericRetryer() {
|
private static Retryer<JsonResponse<?>> getDefaultGenericRetryer(String name) {
|
||||||
return RetryerBuilder.<JsonResponse<?>>newBuilder()
|
return RetryerBuilder.<JsonResponse<?>>newBuilder()
|
||||||
// 异常就重试
|
// 异常就重试
|
||||||
.retryIfException()
|
.retryIfException()
|
||||||
@ -96,7 +96,7 @@ public class WvpService {
|
|||||||
// 重试次数
|
// 重试次数
|
||||||
.withStopStrategy(StopStrategies.stopAfterAttempt(DEFAULT_RETRY_TIME))
|
.withStopStrategy(StopStrategies.stopAfterAttempt(DEFAULT_RETRY_TIME))
|
||||||
.retryIfResult(result -> result != null && (result.getCode() != 0 || result.getCode() != 200))
|
.retryIfResult(result -> result != null && (result.getCode() != 0 || result.getCode() != 200))
|
||||||
.withRetryListener(defaultRetryListener())
|
.withRetryListener(defaultRetryListener(name))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class WvpService {
|
|||||||
String channelId = wvpProxyDevice.getGbDeviceChannelId();
|
String channelId = wvpProxyDevice.getGbDeviceChannelId();
|
||||||
log.info("设备编码 (deviceCode=>{}) 查询到的设备信息 国标id(gbDeviceId => {}), 通道(channelId => {})", deviceCode, deviceId, channelId);
|
log.info("设备编码 (deviceCode=>{}) 查询到的设备信息 国标id(gbDeviceId => {}), 通道(channelId => {})", deviceCode, deviceId, channelId);
|
||||||
|
|
||||||
Retryer<JsonResponse<?>> genericRetryer = getDefaultGenericRetryer();
|
Retryer<JsonResponse<?>> genericRetryer = getDefaultGenericRetryer("调用 wvp api 查询设备历史");
|
||||||
AsyncContext asyncContext = request.startAsync();
|
AsyncContext asyncContext = request.startAsync();
|
||||||
asyncContext.setTimeout(0);
|
asyncContext.setTimeout(0);
|
||||||
asyncContext.start(() -> {
|
asyncContext.start(() -> {
|
||||||
@ -177,24 +177,27 @@ public class WvpService {
|
|||||||
return JsonResponse.success(null);
|
return JsonResponse.success(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonResponse<QueryRecordResp> queryRecord = wvpProxyClient.queryRecord(token, deviceId, channelId, new QueryRecordReq(DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)));
|
Retryer<JsonResponse<List<QueryRecordResp.RecordListDTO>>> queryRecordRetryer = getDefaultRetryer("调用 wvp 设备历史查询 api");
|
||||||
QueryRecordResp queryRecordData = queryRecord.getData();
|
JsonResponse<List<QueryRecordResp.RecordListDTO>> recordListResponse = queryRecordRetryer.call(() -> {
|
||||||
if (queryRecordData == null) {
|
JsonResponse<QueryRecordResp> queryRecord = wvpProxyClient.queryRecord(token, deviceId, channelId, new QueryRecordReq(DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)));
|
||||||
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 错误信息: {3}", deviceCode, deviceId, channelId, queryRecord.getMsg());
|
QueryRecordResp queryRecordData = queryRecord.getData();
|
||||||
log.error(reason);
|
if (queryRecordData == null) {
|
||||||
log.error("查询历史录像 返回结果 => {}", queryRecord);
|
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 错误信息: {3}", deviceCode, deviceId, channelId, queryRecord.getMsg());
|
||||||
writeErrorToResponse(response, JsonResponse.error(reason));
|
log.error(reason);
|
||||||
return null;
|
log.error("查询历史录像 返回结果 => {}", queryRecord);
|
||||||
}
|
throw new JsonException(reason);
|
||||||
List<QueryRecordResp.RecordListDTO> recordList = queryRecordData.getRecordList();
|
}
|
||||||
if (CollectionUtils.isEmpty(recordList)) {
|
List<QueryRecordResp.RecordListDTO> recordList = queryRecordData.getRecordList();
|
||||||
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 查询时间范围 开始时间: {3}, 结束时间: {4}, 录像数量为 0", deviceCode, deviceId, channelId, startTime, endTime);
|
if (CollectionUtils.isEmpty(recordList)) {
|
||||||
writeErrorToResponse(response, JsonResponse.error(reason));
|
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 查询时间范围 开始时间: {3}, 结束时间: {4}, 录像数量为 0", deviceCode, deviceId, channelId, startTime, endTime);
|
||||||
return null;
|
throw new JsonException(reason);
|
||||||
}
|
}
|
||||||
log.info("通过 wvp 查询到 {} 条历史录像 设备: {}, 国标id: {}, 通道: {}, 开始时间: {}, 结束时间: {}", recordList.size(), deviceCode, deviceId, channelId, startTime, endTime);
|
log.info("通过 wvp 查询到 {} 条历史录像 设备: {}, 国标id: {}, 通道: {}, 开始时间: {}, 结束时间: {}", recordList.size(), deviceCode, deviceId, channelId, startTime, endTime);
|
||||||
|
return JsonResponse.success(recordList);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
downloadService.download(response, "http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
|
downloadService.download(response, "http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
|
||||||
return queryRecord;
|
return login;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user