Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: make log web sockets logic more clear
  • Loading branch information
Parkreiner committed Jul 2, 2024
commit 460aa53adbff7a718a8e356bfb1c97f3fb644df6
12 changes: 9 additions & 3 deletions site/src/modules/resources/AgentLogs/useAgentLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ export function useAgentLogs(
const queryOptions = agentLogs(workspaceId, agentId);
const { data: logs, isFetched } = useQuery({ ...queryOptions, enabled });

// Track the ID of the last log received when the initial logs response comes
// back. If the logs are not complete, the ID will mark the start point of the
// Web sockets response so that the remaining logs can be received over time
const lastQueriedLogId = useRef(0);
useEffect(() => {
const lastLog = logs?.at(-1);
const canSetLogId = lastLog !== undefined && lastQueriedLogId.current === 0;
const isAlreadyTracking = lastQueriedLogId.current !== 0;
if (isAlreadyTracking) {
return;
}

if (canSetLogId) {
const lastLog = logs?.at(-1);
if (lastLog !== undefined) {
lastQueriedLogId.current = lastLog.id;
}
}, [logs]);
Expand Down