fix(replay): recover failed archives and release deleted sessions
This commit is contained in:
@@ -52,6 +52,20 @@ export interface ObservationReplayCoordinator {
|
||||
cancel: () => void;
|
||||
}
|
||||
|
||||
export async function deleteObservationSessionAfterTeardown(
|
||||
sessionId: string,
|
||||
{
|
||||
onDeleteBegin,
|
||||
deleteSession = deleteObservationSession,
|
||||
}: {
|
||||
onDeleteBegin?: (sessionId: string) => void | Promise<void>;
|
||||
deleteSession?: (sessionId: string) => Promise<void>;
|
||||
} = {},
|
||||
): Promise<void> {
|
||||
await onDeleteBegin?.(sessionId);
|
||||
await deleteSession(sessionId);
|
||||
}
|
||||
|
||||
export interface ObservationPreparationPollingOptions {
|
||||
signal: AbortSignal;
|
||||
fetcher?: ObservationSessionFetch;
|
||||
@@ -375,6 +389,7 @@ export function useObservationSessions({
|
||||
onReplayBegin,
|
||||
onReplayAccepted,
|
||||
onReplaySettled,
|
||||
onDeleteBegin,
|
||||
}: {
|
||||
limit?: number;
|
||||
scope?: ObservationSessionScope;
|
||||
@@ -392,6 +407,8 @@ export function useObservationSessions({
|
||||
session: ObservationSessionSummary,
|
||||
outcome: ObservationReplayOutcome,
|
||||
) => void | Promise<void>;
|
||||
/** Releases an active viewer before its evidence and derived cache are deleted. */
|
||||
onDeleteBegin?: (sessionId: string) => void | Promise<void>;
|
||||
} = {}): ObservationSessionsController {
|
||||
const [items, setItems] = useState<ObservationSessionSummary[]>([]);
|
||||
const [state, setState] = useState<ObservationSessionsLoadState>("idle");
|
||||
@@ -606,7 +623,7 @@ export function useObservationSessions({
|
||||
setDeletingSessionId(sessionId);
|
||||
setError(null);
|
||||
try {
|
||||
await deleteObservationSession(sessionId);
|
||||
await deleteObservationSessionAfterTeardown(sessionId, { onDeleteBegin });
|
||||
if (!mounted.current) return false;
|
||||
setItems((current) => current.filter((item) => item.id !== sessionId));
|
||||
setFailedSessionId((current) => current === sessionId ? null : current);
|
||||
@@ -617,7 +634,7 @@ export function useObservationSessions({
|
||||
} finally {
|
||||
if (mounted.current) setDeletingSessionId(null);
|
||||
}
|
||||
}, [deletingSessionId, replayingSessionId]);
|
||||
}, [deletingSessionId, onDeleteBegin, replayingSessionId]);
|
||||
|
||||
return {
|
||||
items,
|
||||
|
||||
Reference in New Issue
Block a user