Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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) => {
if (!iso) return false
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 () => {
Expand All @@ -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 })
Expand Down