File size: 943 Bytes
c09f67c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
 * Threshold in milliseconds for considering a pending document as "stale"
 * Documents pending for longer than this are likely stuck and need retry
 */
const STALE_PROCESSING_THRESHOLD_MS = 10 * 60 * 1000; // 10 minutes

/**
 * Check if a document is stuck in processing (pending for >10 minutes)
 * Used to show retry options instead of infinite loading skeletons
 *
 * A document is considered stale if:
 * - Status is "pending"
 * - It was created more than 10 minutes ago
 *
 * Documents with a title that are pending for a long time are likely
 * stuck (status never updated to completed), not being reprocessed.
 */
export function isStaleProcessing(
  processingStatus: string | null | undefined,
  createdAt: string | Date | null | undefined,
): boolean {
  if (processingStatus !== "pending" || !createdAt) {
    return false;
  }

  return (
    Date.now() - new Date(createdAt).getTime() > STALE_PROCESSING_THRESHOLD_MS
  );
}