diff --git a/packages/retryable-monitor/handlers/notion/alertUntriagedRetraybles.ts b/packages/retryable-monitor/handlers/notion/alertUntriagedRetraybles.ts index 6c49a22..34b0ee9 100644 --- a/packages/retryable-monitor/handlers/notion/alertUntriagedRetraybles.ts +++ b/packages/retryable-monitor/handlers/notion/alertUntriagedRetraybles.ts @@ -13,7 +13,7 @@ const formatDate = (iso: string | undefined) => { hour12: false, timeZone: 'UTC', timeZoneName: 'short', - }).format(date) // e.g. "Jun 6, 2025, 04:51 UTC" + }).format(date) } const isNearExpiry = (iso: string | undefined, hours = 24) => { @@ -21,7 +21,7 @@ const isNearExpiry = (iso: string | undefined, hours = 24) => { const expiry = new Date(iso).getTime() const now = Date.now() const timeLeftMs = expiry - now - return timeLeftMs <= hours * 60 * 60 * 1000 + return timeLeftMs > 0 && timeLeftMs <= hours * 60 * 60 * 1000 } export const alertUntriagedNotionRetryables = async () => { @@ -46,28 +46,33 @@ export const alertUntriagedNotionRetryables = async () => { for (const page of response.results) { const props = (page as any).properties + const status = props?.Status?.select?.name || '(unknown)' + if (status === 'Expired') continue + const timeoutRaw = props?.timeoutTimestamp?.date?.start const timeoutStr = formatDate(timeoutRaw) const retryableUrl = props?.ChildTx?.title?.[0]?.text?.content || '(unknown)' + const parentTx = props?.ParentTx?.rich_text?.[0]?.text?.content || '(unknown)' + const deposit = props?.TotalRetryableDeposit?.rich_text?.[0]?.text?.content || '(unknown)' const decision = props?.Decision?.select?.name || '(unknown)' - const expiryTime = timeoutRaw ? new Date(timeoutRaw).getTime() : Infinity const now = Date.now() + const expiryTime = timeoutRaw ? new Date(timeoutRaw).getTime() : Infinity const hoursLeft = (expiryTime - now) / (1000 * 60 * 60) let message = '' if (decision === 'Triage') { if (hoursLeft <= 72) { - message = `🚨🚨 Retryable ticket needs **IMMEDIATE** triage (expires soon!):\n• Retryable: ${retryableUrl}\n• Timeout: ${timeoutStr}\n→ Please triage urgently.` + message = `🚨🚨 Retryable ticket needs IMMEDIATE triage (expires soon!):\n• Retryable: ${retryableUrl}\n• Timeout: ${timeoutStr}\n• Parent Tx: ${parentTx}\n• Deposit: ${deposit}\n→ Please triage urgently.` } else { - message = `⚠️ Retryable ticket needs triage:\n• Retryable: ${retryableUrl}\n• Timeout: ${timeoutStr}\n→ Please review and decide whether to redeem or ignore.` + message = `⚠️ Retryable ticket needs triage:\n• Retryable: ${retryableUrl}\n• Timeout: ${timeoutStr}\n• Parent Tx: ${parentTx}\n• Deposit: ${deposit}\n→ Please review and decide whether to redeem or ignore.` } } else if (decision === 'Should Redeem') { - if (!isNearExpiry(timeoutRaw)) continue // Skip if not near expiry - message = `🚨 Retryable marked for redemption and nearing expiry:\n• Retryable: ${retryableUrl}\n• Timeout: ${timeoutStr}\n→ Check why it hasn't been executed.` + if (!isNearExpiry(timeoutRaw)) continue + message = `🚨 Retryable marked for redemption and nearing expiry:\n• Retryable: ${retryableUrl}\n• Timeout: ${timeoutStr}\n• Parent Tx: ${parentTx}\n• Deposit: ${deposit}\n→ Check why it hasn't been executed.` } else { - continue // skip unexpected decisions + continue } await postSlackMessage({ message })