timeout no error

This commit is contained in:
Donghuang 2021-10-11 17:24:32 +08:00
parent d55ae1b336
commit 122b49431c
3 changed files with 12 additions and 6 deletions

View File

@ -13,7 +13,6 @@ import com.pudonghot.yo.model.exception.ErrorCode;
import com.pudonghot.yo.openapi.auth.SessionAbility;
import com.pudonghot.yo.service.CommonAgentStatusService;
import com.pudonghot.yo.openapi.service.AgentEventService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.async.DeferredResult;
@ -30,8 +29,7 @@ public class AgentEventController implements SessionAbility {
private CommonAgentStatusService agentStatusService;
@Autowired
private AgentEventService agentEventService;
@Value("${yo.server.web-async-timeout:48000}")
private Long webAsyncTimeout;
private final Object EMPTY = new Object();
@RequestMapping("/resource/agentevent/{account}")
public DeferredResult<?> agentEvent(
@ -44,7 +42,7 @@ public class AgentEventController implements SessionAbility {
new Search(Agent.TENANT_ID, getTenantId())
.eq(Agent.ACCOUNT, account));
val result = new DeferredResult<Object>(webAsyncTimeout);
val result = new DeferredResult<Object>();
if (agent == null) {
result.setResult(errorModel(ErrorCode.AGENT_NOT_FOUND));
@ -78,7 +76,10 @@ public class AgentEventController implements SessionAbility {
if (!agentEventService.fetchTempEvent(agent, result)) {
agentEventService.put(eventKey, result);
result.onCompletion(() -> agentEventService.remove(eventKey, result));
result.onTimeout(() -> agentEventService.remove(eventKey, result));
result.onTimeout(() -> {
result.setResult(EMPTY);
agentEventService.remove(eventKey, result);
});
}
agentEventService.updateSession(agent);

View File

@ -3,6 +3,7 @@ package com.pudonghot.yo.openapi.response;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;
import com.pudonghot.yo.model.agentevent.AgentEvent;
@ -14,6 +15,8 @@ import com.pudonghot.yo.model.agentevent.AgentEvent;
@Getter
@ToString
@RequiredArgsConstructor
public class RespAgentEvent {
public class RespAgentEvent implements Serializable {
private static final long serialVersionUID = 1L;
private final AgentEvent event;
}

View File

@ -55,6 +55,8 @@ dubbo:
base-packages: com.pudonghot.yo
yo:
server:
web-async-timeout: 14600
datasource:
url: jdbc:mysql://172.16.4.6/yoqw?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
username: yoqw