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
polish(polling): extract lock TTL constant and remove unnecessary typ…
…e casts

- Widen processPolledWebhookEvent body param to accept object, eliminating
  `as unknown as Record<string, unknown>` double casts in all 4 handlers
- Extract LOCK_TTL_SECONDS constant in route, tying maxDuration and lock TTL
  to a single value

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
waleedlatif1 and claude committed Apr 8, 2026
commit 21f49cce9499f703e59939514d407a879ef51359
7 changes: 5 additions & 2 deletions apps/sim/app/api/webhooks/poll/[provider]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { pollProvider, VALID_POLLING_PROVIDERS } from '@/lib/webhooks/polling'

const logger = createLogger('PollingAPI')

/** Lock TTL in seconds — matches maxDuration so the lock auto-expires if the function times out. */
const LOCK_TTL_SECONDS = 180

export const dynamic = 'force-dynamic'
export const maxDuration = 180
export const maxDuration = LOCK_TTL_SECONDS

export async function GET(
request: NextRequest,
Expand All @@ -29,7 +32,7 @@ export async function GET(
if (authError) return authError

lockValue = requestId
const locked = await acquireLock(LOCK_KEY, lockValue, 180)
const locked = await acquireLock(LOCK_KEY, lockValue, LOCK_TTL_SECONDS)
if (!locked) {
return NextResponse.json(
{
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/webhooks/polling/gmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ async function processEmails(
const result = await processPolledWebhookEvent(
webhookData,
workflowData,
webhookPayload as unknown as Record<string, unknown>,
webhookPayload,
requestId
)

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/webhooks/polling/imap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ async function processEmails(
const result = await processPolledWebhookEvent(
webhookData,
workflowData,
payload as unknown as Record<string, unknown>,
payload,
requestId
)

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/webhooks/polling/outlook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ async function processOutlookEmails(
const result = await processPolledWebhookEvent(
webhookData,
workflowData,
payload as unknown as Record<string, unknown>,
payload,
requestId
)

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/webhooks/polling/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async function processRssItems(
const result = await processPolledWebhookEvent(
webhookData,
workflowData,
payload as unknown as Record<string, unknown>,
payload,
requestId
)

Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/webhooks/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ interface PolledWorkflowRecord {
export async function processPolledWebhookEvent(
foundWebhook: PolledWebhookRecord,
foundWorkflow: PolledWorkflowRecord,
body: Record<string, unknown>,
body: Record<string, unknown> | object,
requestId: string
): Promise<PolledWebhookEventResult> {
if (!foundWebhook.provider) {
Expand Down
Loading