fix(sync): skip duplicate status events (#1152)
* fix(sync): skip duplicate status events * test(sync): cover duplicate idle statuses --------- Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
Bohdan Triapitsyn
parent
c1c21fe340
commit
14c0bfe0bc
@@ -90,6 +90,18 @@ function shouldPreserveExistingPart(previous: Part, next: Part): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
function areSessionStatusesEqual(left: SessionStatus | undefined, right: SessionStatus): boolean {
|
||||
if (left === right) return true
|
||||
if (!left || left.type !== right.type) return false
|
||||
if (left.type === "retry") {
|
||||
return right.type === "retry"
|
||||
&& left.attempt === right.attempt
|
||||
&& left.message === right.message
|
||||
&& left.next === right.next
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global events
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -219,19 +231,30 @@ export function applyDirectoryEvent(
|
||||
|
||||
case "session.status": {
|
||||
const props = event.properties as { sessionID: string; status: SessionStatus }
|
||||
if (areSessionStatusesEqual(draft.session_status[props.sessionID], props.status)) {
|
||||
return false
|
||||
}
|
||||
draft.session_status[props.sessionID] = props.status
|
||||
return true
|
||||
}
|
||||
|
||||
case "session.idle": {
|
||||
const props = event.properties as { sessionID: string }
|
||||
draft.session_status[props.sessionID] = { type: "idle" }
|
||||
const status = { type: "idle" } as const
|
||||
if (areSessionStatusesEqual(draft.session_status[props.sessionID], status)) {
|
||||
return false
|
||||
}
|
||||
draft.session_status[props.sessionID] = status
|
||||
return true
|
||||
}
|
||||
|
||||
case "session.error": {
|
||||
const props = event.properties as { sessionID: string }
|
||||
draft.session_status[props.sessionID] = { type: "idle" }
|
||||
const status = { type: "idle" } as const
|
||||
if (areSessionStatusesEqual(draft.session_status[props.sessionID], status)) {
|
||||
return false
|
||||
}
|
||||
draft.session_status[props.sessionID] = status
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user