MCPcopy
hub / github.com/simstudioai/sim / dispatchImportJob

Function dispatchImportJob

apps/sim/lib/copilot/tools/server/table/user-table.ts:134–153  ·  view source on GitHub ↗

* Dispatches a background import for an already-claimed job slot, mirroring the * import-async routes: trigger.dev when enabled (survives deploys, retries), * detached in-process worker otherwise. A failed dispatch releases the claim so * a ghost `running` job can't hold the table's one-write-job

(payload: TableImportPayload)

Source from the content-addressed store, hash-verified

132 * a ghost `running` job can't hold the table's one-write-job slot.
133 */
134async function dispatchImportJob(payload: TableImportPayload): Promise<void> {
135 if (isTriggerDevEnabled) {
136 try {
137 const [{ tableImportTask }, { tasks }, { resolveTriggerRegion }] = await Promise.all([
138 import('@/background/table-import'),
139 import('@trigger.dev/sdk'),
140 import('@/lib/core/async-jobs/region'),
141 ])
142 await tasks.trigger<typeof tableImportTask>('table-import', payload, {
143 tags: [`tableId:${payload.tableId}`, `jobId:${payload.importId}`],
144 region: await resolveTriggerRegion(),
145 })
146 } catch (error) {
147 await releaseJobClaim(payload.tableId, payload.importId).catch(() => {})
148 throw error
149 }
150 } else {
151 runDetached('table-import', () => runTableImport(payload))
152 }
153}
154
155/**
156 * Dispatches a background filter-delete for an already-claimed job slot,

Callers 1

executeFunction · 0.85

Calls 4

releaseJobClaimFunction · 0.90
runDetachedFunction · 0.90
runTableImportFunction · 0.90
resolveTriggerRegionFunction · 0.85

Tested by

no test coverage detected