| 1519 | } |
| 1520 | |
| 1521 | export async function markDocumentAsFailedTimeout( |
| 1522 | documentId: string, |
| 1523 | processingStartedAt: Date, |
| 1524 | requestId: string |
| 1525 | ): Promise<{ success: boolean; processingDuration: number }> { |
| 1526 | const now = new Date() |
| 1527 | const processingDuration = now.getTime() - processingStartedAt.getTime() |
| 1528 | const DEAD_PROCESS_THRESHOLD_MS = 600 * 1000 // 10 minutes |
| 1529 | |
| 1530 | if (processingDuration <= DEAD_PROCESS_THRESHOLD_MS) { |
| 1531 | throw new Error('Document has not been processing long enough to be considered dead') |
| 1532 | } |
| 1533 | |
| 1534 | await db |
| 1535 | .update(document) |
| 1536 | .set({ |
| 1537 | processingStatus: 'failed', |
| 1538 | processingError: 'Processing timed out. Please retry or re-sync the connector.', |
| 1539 | processingCompletedAt: now, |
| 1540 | }) |
| 1541 | .where(eq(document.id, documentId)) |
| 1542 | |
| 1543 | logger.info( |
| 1544 | `[${requestId}] Marked document ${documentId} as failed due to dead process (processing time: ${Math.round(processingDuration / 1000)}s)` |
| 1545 | ) |
| 1546 | |
| 1547 | return { |
| 1548 | success: true, |
| 1549 | processingDuration, |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | export async function retryDocumentProcessing( |
| 1554 | knowledgeBaseId: string, |