Commit a1b2130
authored
improvement(knowledge): batch trigger dispatch, prune redundant DB roundtrips (#4680)
* improvement(knowledge): batch trigger dispatch, prune redundant DB roundtrips
Connector sync was dispatching Trigger.dev document-processing jobs one
HTTP roundtrip at a time. processDocumentsWithQueue now uses
tasks.batchTrigger when Trigger.dev is available, collapsing N roundtrips
to ceil(N/1000). Idempotency keys protect against duplicate runs on retry.
Also trims DB roundtrips inside the sync loop:
- Per-batch isConnectorDeleted + isKnowledgeBaseDeleted collapsed into a
single checkSyncLiveness JOIN (one SELECT instead of two per batch).
- Dropped redundant pre-upload isKnowledgeBaseDeleted checks from
addDocument/updateDocument: the batch-boundary liveness check already
catches pre-batch deletions and the in-tx FOR UPDATE is authoritative
for races during the batch.
- Removed dead processDocumentsWithTrigger helper (never called).
* refactor(knowledge): split dispatch helpers, drop dead trigger branch
- Use the canonical DocumentProcessingPayload from the task module instead
of the duplicate DocumentJobData interface in service.ts
- Pass typeof processDocumentTask as a generic to tasks.batchTrigger so the
payload shape is type-checked against the task definition
- Inline TRIGGER_BATCH_SIZE provenance (Trigger.dev SDK 4.3.1+ doc'd cap,
we're on 4.4.3)
- Split direct vs trigger dispatch into dispatchInProcess and
dispatchViaBatchTrigger; collapse the all-failed throw into a single
check on the combined dispatched counter
- Remove dispatchDocumentProcessingJob — its trigger branch is no longer
reachable now that batchTrigger handles the trigger path, and the direct
branch is inlined
* improvement(knowledge): log Trigger.dev batchIds for audit trail
tasks.batchTrigger returns a batchId per call. Collecting and logging
them after dispatch makes it possible to look up or cancel batches in
the Trigger.dev dashboard when investigating stuck or missing documents.
* improvement(knowledge): thread requestId through direct dispatch logs
Symmetry polish: dispatchInProcess now includes [requestId] in its error
log so direct-mode failures are correlatable the same way trigger-mode
failures already are.
* improvement(knowledge): trim verbose comments
Tightens TSDoc on processDocumentsWithQueue, TRIGGER_BATCH_SIZE,
checkSyncLiveness, and the idempotency-key inline comment.1 parent c381550 commit a1b2130
2 files changed
Lines changed: 120 additions & 123 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
63 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | | - | |
| 73 | + | |
| 74 | + | |
66 | 75 | | |
67 | | - | |
68 | | - | |
69 | 76 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
| |||
502 | 510 | | |
503 | 511 | | |
504 | 512 | | |
505 | | - | |
| 513 | + | |
| 514 | + | |
506 | 515 | | |
507 | 516 | | |
508 | | - | |
| 517 | + | |
509 | 518 | | |
510 | 519 | | |
511 | 520 | | |
| |||
642 | 651 | | |
643 | 652 | | |
644 | 653 | | |
645 | | - | |
646 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
647 | 657 | | |
648 | 658 | | |
649 | | - | |
| 659 | + | |
650 | 660 | | |
651 | 661 | | |
652 | 662 | | |
| |||
881 | 891 | | |
882 | 892 | | |
883 | 893 | | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | 894 | | |
888 | 895 | | |
889 | 896 | | |
| |||
963 | 970 | | |
964 | 971 | | |
965 | 972 | | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | 973 | | |
970 | 974 | | |
971 | 975 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | 108 | | |
135 | 109 | | |
136 | 110 | | |
| |||
314 | 288 | | |
315 | 289 | | |
316 | 290 | | |
317 | | - | |
318 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
319 | 296 | | |
320 | 297 | | |
321 | 298 | | |
322 | | - | |
323 | | - | |
| 299 | + | |
| 300 | + | |
324 | 301 | | |
325 | 302 | | |
326 | 303 | | |
| |||
331 | 308 | | |
332 | 309 | | |
333 | 310 | | |
334 | | - | |
| 311 | + | |
| 312 | + | |
335 | 313 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
341 | 329 | | |
342 | 330 | | |
343 | | - | |
344 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
345 | 335 | | |
346 | 336 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
353 | 340 | | |
354 | 341 | | |
355 | | - | |
| 342 | + | |
356 | 343 | | |
357 | 344 | | |
358 | | - | |
359 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
360 | 384 | | |
| 385 | + | |
| 386 | + | |
361 | 387 | | |
362 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
363 | 404 | | |
364 | 405 | | |
365 | 406 | | |
| |||
698 | 739 | | |
699 | 740 | | |
700 | 741 | | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | 742 | | |
750 | 743 | | |
751 | 744 | | |
| |||
0 commit comments