Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
removed comments
  • Loading branch information
waleedlatif1 committed Apr 9, 2026
commit a0c2a75bef5e30d45a9d156f62e3610dbcedc47e
6 changes: 0 additions & 6 deletions apps/sim/app/api/webhooks/poll/[provider]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export async function GET(
return NextResponse.json({ error: `Unknown polling provider: ${provider}` }, { status: 404 })
}

// When trigger.dev is enabled, dispatch polling as an async task and return immediately.
// Per-provider concurrency (concurrencyKey) ensures only one poll per provider runs at a time,
// while different providers (gmail vs outlook) can poll in parallel.
if (isTriggerDevEnabled) {
try {
const handle = await providerPolling.trigger(
Expand All @@ -55,7 +52,6 @@ export async function GET(
status: 'dispatched',
})
} catch (triggerError) {
// If trigger.dev is unavailable, fall through to synchronous polling below.
logger.warn(
`[${requestId}] Trigger.dev dispatch failed for ${provider}, falling back to synchronous polling`,
{
Expand All @@ -65,8 +61,6 @@ export async function GET(
}
}

// Fallback: synchronous polling when trigger.dev is not enabled (self-hosted).
// Redis lock prevents concurrent polls for the same provider.
const LOCK_KEY = `${provider}-polling-lock`
let lockValue: string | undefined

Expand Down
6 changes: 1 addition & 5 deletions apps/sim/lib/webhooks/polling/gmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ async function fetchNewEmails(

logger.info(`[${requestId}] Falling back to search API after history API error ${status}`)
const searchResult = await searchEmails(accessToken, config, requestId, logger)
// When search finds 0 emails after a history API failure, the stored historyId is likely
// invalid. Fetch a fresh one from the profile API to break the potential 404 retry loop.
if (searchResult.emails.length === 0) {
const freshHistoryId = await getGmailProfileHistoryId(accessToken, requestId, logger)
if (freshHistoryId) {
Expand Down Expand Up @@ -491,9 +489,7 @@ async function processEmails(
if (headers.date) {
try {
date = new Date(headers.date).toISOString()
} catch (_e) {
// Keep date as null if parsing fails
}
} catch (_e) {}
} else if (email.internalDate) {
date = new Date(Number.parseInt(email.internalDate)).toISOString()
}
Expand Down
21 changes: 5 additions & 16 deletions apps/sim/lib/webhooks/polling/imap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface ImapWebhookConfig {
includeAttachments: boolean
lastProcessedUid?: number
lastProcessedUidByMailbox?: Record<string, number>
/** Stores the UIDVALIDITY value per mailbox as strings (bigint cannot be JSON-serialized). */
uidValidityByMailbox?: Record<string, string>
lastCheckedTimestamp?: string
maxEmailsPerPoll?: number
Expand Down Expand Up @@ -173,9 +172,7 @@ export const imapPollingHandler: PollingProviderHandler = {
} catch (innerError) {
try {
await client.logout()
} catch {
// Ignore logout errors
}
} catch {}
throw innerError
}
} catch (error) {
Expand Down Expand Up @@ -362,9 +359,7 @@ function extractTextFromSource(source: Buffer): { text: string; html: string } {
if (lowerPart.includes('base64')) {
try {
text = Buffer.from(text.replace(/\s/g, ''), 'base64').toString('utf-8')
} catch {
// Keep as-is if base64 decode fails
}
} catch {}
}
}
} else if (lowerPart.includes('content-type: text/html')) {
Expand All @@ -379,9 +374,7 @@ function extractTextFromSource(source: Buffer): { text: string; html: string } {
if (lowerPart.includes('base64')) {
try {
html = Buffer.from(html.replace(/\s/g, ''), 'base64').toString('utf-8')
} catch {
// Keep as-is if base64 decode fails
}
} catch {}
}
}
}
Expand Down Expand Up @@ -436,9 +429,7 @@ function extractAttachmentsFromSource(
mimeType,
size: buffer.length,
})
} catch {
// Skip if decode fails
}
} catch {}
}
}
}
Expand Down Expand Up @@ -582,9 +573,7 @@ async function processEmails(
if (lockState.lock) {
try {
lockState.lock.release()
} catch {
// Ignore lock release errors
}
} catch {}
}
}

Expand Down