Skip to content
Merged
Show file tree
Hide file tree
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 @@ -3,31 +3,36 @@ import { type NextRequest, NextResponse } from 'next/server'
import { verifyCronAuth } from '@/lib/auth/internal'
import { acquireLock, releaseLock } from '@/lib/core/config/redis'
import { generateShortId } from '@/lib/core/utils/uuid'
import { pollRssWebhooks } from '@/lib/webhooks/rss-polling-service'
import { pollProvider, VALID_POLLING_PROVIDERS } from '@/lib/webhooks/polling'

const logger = createLogger('RssPollingAPI')
const logger = createLogger('PollingAPI')

export const dynamic = 'force-dynamic'
export const maxDuration = 180 // Allow up to 3 minutes for polling to complete
/** Lock TTL in seconds — must match maxDuration so the lock auto-expires if the function times out. */
const LOCK_TTL_SECONDS = 180

const LOCK_KEY = 'rss-polling-lock'
const LOCK_TTL_SECONDS = 180 // Same as maxDuration (3 min)
export const dynamic = 'force-dynamic'
export const maxDuration = 180

export async function GET(request: NextRequest) {
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ provider: string }> }
) {
const { provider } = await params
const requestId = generateShortId()
logger.info(`RSS webhook polling triggered (${requestId})`)

const LOCK_KEY = `${provider}-polling-lock`
let lockValue: string | undefined

try {
const authError = verifyCronAuth(request, 'RSS webhook polling')
if (authError) {
return authError
const authError = verifyCronAuth(request, `${provider} webhook polling`)
if (authError) return authError

if (!VALID_POLLING_PROVIDERS.has(provider)) {
return NextResponse.json({ error: `Unknown polling provider: ${provider}` }, { status: 404 })
}

lockValue = requestId
const locked = await acquireLock(LOCK_KEY, lockValue, LOCK_TTL_SECONDS)

if (!locked) {
return NextResponse.json(
{
Expand All @@ -40,21 +45,21 @@ export async function GET(request: NextRequest) {
)
}

const results = await pollRssWebhooks()
const results = await pollProvider(provider)

return NextResponse.json({
success: true,
message: 'RSS polling completed',
message: `${provider} polling completed`,
requestId,
status: 'completed',
...results,
})
} catch (error) {
logger.error(`Error during RSS polling (${requestId}):`, error)
logger.error(`Error during ${provider} polling (${requestId}):`, error)
return NextResponse.json(
{
success: false,
message: 'RSS polling failed',
message: `${provider} polling failed`,
error: error instanceof Error ? error.message : 'Unknown error',
requestId,
},
Expand Down
68 changes: 0 additions & 68 deletions apps/sim/app/api/webhooks/poll/gmail/route.ts

This file was deleted.

68 changes: 0 additions & 68 deletions apps/sim/app/api/webhooks/poll/imap/route.ts

This file was deleted.

68 changes: 0 additions & 68 deletions apps/sim/app/api/webhooks/poll/outlook/route.ts

This file was deleted.

Loading
Loading