Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(db): role-keyed dbFor clients for cleanup and exec workloads#5583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c47223
feat(db): role-keyed dbFor clients for cleanup and exec workloads
TheodoreSpeaks 65cc4c5
fix(db): keep cleanup-invoked helpers and snapshot reads on their rol…
TheodoreSpeaks ee5d5ed
fix(db): dbFor falls back to the process-role URL, not the base URL
TheodoreSpeaks c46b784
feat(db): log which connection each dbFor sub-pool resolved to
TheodoreSpeaks d106359
feat(db): route pause/resume and large-value metadata persistence to …
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { db } from '@sim/db' | ||
| import { dbFor } from '@sim/db' | ||
| import { | ||
| copilotAsyncToolCalls, | ||
| copilotChats, | ||
| @@ -22,6 +22,9 @@ import { prepareChatCleanup } from '@/lib/cleanup/chat-cleanup' | ||
| const logger = createLogger('CleanupTasks') | ||
| /** All cleanup queries run on the dedicated cleanup pool. */ | ||
| const cleanupDb = dbFor('cleanup') | ||
TheodoreSpeaks marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Delete copilot run checkpoints and async tool calls via join through copilotRuns. | ||
| * These tables don't have a direct workspaceId — we find qualifying run IDs first. | ||
| @@ -47,7 +50,7 @@ async function cleanupRunChildren( | ||
| if (workspaceIds.length === 0) return [] | ||
| const runIds = await selectRowsByIdChunks(workspaceIds, (chunkIds, chunkLimit) => | ||
| db | ||
| cleanupDb | ||
| .select({ id: copilotRuns.id }) | ||
| .from(copilotRuns) | ||
| .where( | ||
| @@ -63,7 +66,9 @@ async function cleanupRunChildren( | ||
| const ids = runIds.map((r) => r.id) | ||
| return Promise.all( | ||
| RUN_CHILD_TABLES.map((t) => deleteRowsById(t.table, t.runIdCol, ids, `${label}/${t.name}`)) | ||
| RUN_CHILD_TABLES.map((t) => | ||
| deleteRowsById(t.table, t.runIdCol, ids, `${label}/${t.name}`, cleanupDb) | ||
| ) | ||
| ) | ||
| } | ||
| @@ -82,7 +87,7 @@ export async function runCleanupTasks(payload: CleanupJobPayload): Promise<void> | ||
| ) | ||
| const doomedChats = await selectRowsByIdChunks(workspaceIds, (chunkIds, chunkLimit) => | ||
| db | ||
| cleanupDb | ||
| .select({ id: copilotChats.id }) | ||
| .from(copilotChats) | ||
| .where( | ||
| @@ -110,6 +115,7 @@ export async function runCleanupTasks(payload: CleanupJobPayload): Promise<void> | ||
| workspaceIds, | ||
| retentionDate, | ||
| tableName: `${label}/copilotRuns`, | ||
| dbClient: cleanupDb, | ||
| }) | ||
| // Delete copilot chats using the exact IDs collected above so the chat | ||
| @@ -122,7 +128,7 @@ export async function runCleanupTasks(payload: CleanupJobPayload): Promise<void> | ||
| const chatsResult = { deleted: 0, failed: 0 } | ||
| for (const batch of chunkArray(doomedChatIds, DEFAULT_DELETE_CHUNK_SIZE)) { | ||
| try { | ||
| const deleted = await db | ||
| const deleted = await cleanupDb | ||
| .delete(copilotChats) | ||
| .where(and(inArray(copilotChats.id, batch), lt(copilotChats.updatedAt, retentionDate))) | ||
| .returning({ id: copilotChats.id }) | ||
| @@ -141,6 +147,7 @@ export async function runCleanupTasks(payload: CleanupJobPayload): Promise<void> | ||
| workspaceIds, | ||
| retentionDate, | ||
| tableName: `${label}/mothershipInboxTask`, | ||
| dbClient: cleanupDb, | ||
| }) | ||
| const totalDeleted = | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.