调整会话重试次数与间隔
This commit is contained in:
1 parent
be92ddd55d
commit
f51d33af83
5 files changed
+16
-11
No files matched your search
@@ -388,7 +388,8 @@ async def retry_enhanced_session(
|
||||
pty = session_manager.deserialize_pty(record.pty_info)
|
||||
|
||||
last_error: Exception | None = None
|
||||
for attempt in range(1, 4):
|
||||
retry_schedule = [2, 4, 8, 16, 32]
|
||||
for attempt in range(1, len(retry_schedule) + 1):
|
||||
try:
|
||||
await session_manager.close_session(session_id)
|
||||
managed = await session_manager.create_session(
|
||||
@@ -412,7 +413,8 @@ async def retry_enhanced_session(
|
||||
return response
|
||||
except Exception as exc:
|
||||
last_error = exc
|
||||
await asyncio.sleep(5)
|
||||
if attempt < len(retry_schedule):
|
||||
await asyncio.sleep(retry_schedule[attempt - 1])
|
||||
|
||||
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(last_error) if last_error else "重试失败")
|
||||
|
||||
|
||||
@@ -35,10 +35,11 @@ def _serialize_session_status(record: SessionRecord) -> str:
|
||||
|
||||
|
||||
def _required_elapsed_seconds_for_next_retry(retry_cycle_count: int) -> int:
|
||||
# Retry spacing: 5s, 10s, 15s...
|
||||
# Retry spacing (seconds): 2, 4, 8, 16, 32
|
||||
# retry_cycle_count is the number of attempts already made in current cycle.
|
||||
next_attempt = retry_cycle_count + 1
|
||||
return 5 * next_attempt * (next_attempt + 1) // 2
|
||||
schedule = [2, 4, 8, 16, 32]
|
||||
index = min(retry_cycle_count, len(schedule) - 1)
|
||||
return schedule[index]
|
||||
|
||||
|
||||
def build_state() -> tuple[
|
||||
@@ -95,7 +96,7 @@ def build_state() -> tuple[
|
||||
SessionRecord.allow_auto_retry.is_(True),
|
||||
SessionRecord.enhanced_fingerprint.is_not(None),
|
||||
SessionRecord.tmux_binary_path.is_not(None),
|
||||
SessionRecord.retry_cycle_count < 3,
|
||||
SessionRecord.retry_cycle_count < 5,
|
||||
)
|
||||
).scalars().all()
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ export function SessionsDesktop({ state }: SessionsDesktopProps) {
|
||||
) : null}
|
||||
{session.enhanced_enabled && session.status !== "active" && session.allow_auto_retry !== false ? (
|
||||
<p className={`text-xs ${state.isDark ? "text-slate-500" : "text-slate-400"}`}>
|
||||
{state.t("本轮重试", "Retry cycle")}: {session.retry_cycle_count ?? 0}/3
|
||||
{state.t("本轮重试", "Retry cycle")}: {session.retry_cycle_count ?? 0}/5
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -201,7 +201,7 @@ export function useSessionsState() {
|
||||
session.enhanced_enabled === true
|
||||
&& session.status !== "active"
|
||||
&& session.allow_auto_retry !== false
|
||||
&& (session.retry_cycle_count ?? 0) < 3
|
||||
&& (session.retry_cycle_count ?? 0) < 5
|
||||
);
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -184,13 +184,15 @@ export function useTerminalSocket({
|
||||
}
|
||||
|
||||
if (autoReconnect && !event.wasClean && reconnectAttemptRef.current < 5) {
|
||||
const schedule = [2, 4, 8, 16, 32];
|
||||
const attempt = reconnectAttemptRef.current + 1;
|
||||
const delay = attempt * 5000;
|
||||
const delaySeconds = schedule[attempt - 1] ?? schedule[schedule.length - 1];
|
||||
const delay = delaySeconds * 1000;
|
||||
reconnectAttemptRef.current = attempt;
|
||||
|
||||
const reconnectMessage = t(
|
||||
`连接已断开,${Math.round(delay / 1000)}秒后自动重连 (${reconnectAttemptRef.current}/5)...`,
|
||||
`Connection lost. Auto reconnect in ${Math.round(delay / 1000)}s (${reconnectAttemptRef.current}/5)...`
|
||||
`连接已断开,${delaySeconds}秒后自动重连 (${reconnectAttemptRef.current}/5)...`,
|
||||
`Connection lost. Auto reconnect in ${delaySeconds}s (${reconnectAttemptRef.current}/5)...`
|
||||
);
|
||||
term.write(`\r\n\x1b[31m${reconnectMessage}\x1b[0m\r\n`);
|
||||
setReconnectCountdown(Math.round(delay / 1000));
|
||||
|
||||
Reference in new issue
Block a user