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

Function processDocumentsWithQueue

apps/sim/lib/knowledge/documents/service.ts:403–432  ·  view source on GitHub ↗
(
  createdDocuments: DocumentData[],
  knowledgeBaseId: string,
  processingOptions: ProcessingOptions,
  requestId: string
)

Source from the content-addressed store, hash-verified

401 * partial failures are logged and recovered by the next sync's stuck-doc pass.
402 */
403export async function processDocumentsWithQueue(
404 createdDocuments: DocumentData[],
405 knowledgeBaseId: string,
406 processingOptions: ProcessingOptions,
407 requestId: string
408): Promise<void> {
409 if (createdDocuments.length === 0) return
410
411 const jobPayloads = createdDocuments.map((doc) =>
412 buildJobPayload(doc, knowledgeBaseId, processingOptions, requestId)
413 )
414
415 const useTrigger = isTriggerAvailable()
416 logger.info(
417 `[${requestId}] Dispatching background processing for ${jobPayloads.length} documents`,
418 { backend: useTrigger ? 'trigger-dev' : 'direct' }
419 )
420
421 const dispatched = useTrigger
422 ? await dispatchViaBatchTrigger(jobPayloads, requestId)
423 : await dispatchInProcess(jobPayloads, requestId)
424
425 logger.info(
426 `[${requestId}] Document dispatch complete: ${dispatched}/${jobPayloads.length} succeeded`
427 )
428
429 if (dispatched === 0) {
430 throw new Error(`All ${jobPayloads.length} document processing dispatches failed`)
431 }
432}
433
434async function dispatchViaBatchTrigger(
435 jobPayloads: DocumentProcessingPayload[],

Callers 5

executeSyncFunction · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
retryDocumentProcessingFunction · 0.85

Calls 5

isTriggerAvailableFunction · 0.85
dispatchViaBatchTriggerFunction · 0.85
dispatchInProcessFunction · 0.85
infoMethod · 0.80
buildJobPayloadFunction · 0.70

Tested by

no test coverage detected