MCPcopy Index your code
hub / github.com/simstudioai/sim / latestJobsForTables

Function latestJobsForTables

apps/sim/lib/table/jobs/service.ts:108–120  ·  view source on GitHub ↗
(
  tableIds: string[]
)

Source from the content-addressed store, hash-verified

106
107/** Latest non-export job per table for a batch of ids, via `DISTINCT ON (table_id)`. */
108export async function latestJobsForTables(
109 tableIds: string[]
110): Promise<Map<string, DerivedJobFields>> {
111 const map = new Map<string, DerivedJobFields>()
112 if (tableIds.length === 0) return map
113 const rows = await db
114 .selectDistinctOn([tableJobs.tableId], { tableId: tableJobs.tableId, ...JOB_PROJECTION })
115 .from(tableJobs)
116 .where(and(inArray(tableJobs.tableId, tableIds), ne(tableJobs.type, 'export')))
117 .orderBy(tableJobs.tableId, desc(tableJobs.startedAt))
118 for (const row of rows) map.set(row.tableId, mapJobRow(row))
119 return map
120}
121
122/**
123 * Atomically claims a table's single background-job slot by inserting a `running` row into

Callers 1

listTablesFunction · 0.90

Calls 2

mapJobRowFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected