Skip to content

Commit 37dcde2

Browse files
feat(enterprise-plan-webhooks): skip webhook queue for enterprise plan users (#1250)
* feat(enterprise-plan-webhooks): skip webhook queue for enterprise plan users * reuse subscription record instead of making extra db call
1 parent e31627c commit 37dcde2

File tree

1 file changed

+8
-3
lines changed
  • apps/sim/app/api/webhooks/trigger/[path]

1 file changed

+8
-3
lines changed

apps/sim/app/api/webhooks/trigger/[path]/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export async function POST(
247247
}
248248

249249
// --- PHASE 3: Rate limiting for webhook execution ---
250+
let isEnterprise = false
250251
try {
251252
// Get user subscription for rate limiting
252253
const [subscriptionRecord] = await db
@@ -256,6 +257,7 @@ export async function POST(
256257
.limit(1)
257258

258259
const subscriptionPlan = (subscriptionRecord?.plan || 'free') as SubscriptionPlan
260+
isEnterprise = subscriptionPlan === 'enterprise'
259261

260262
// Check async rate limits (webhooks are processed asynchronously)
261263
const rateLimiter = new RateLimiter()
@@ -333,7 +335,7 @@ export async function POST(
333335
// Continue processing - better to risk usage limit bypass than fail webhook
334336
}
335337

336-
// --- PHASE 5: Queue webhook execution (trigger.dev or direct based on env) ---
338+
// --- PHASE 5: Queue webhook execution (trigger.dev or direct based on plan/env) ---
337339
try {
338340
const payload = {
339341
webhookId: foundWebhook.id,
@@ -346,7 +348,9 @@ export async function POST(
346348
blockId: foundWebhook.blockId,
347349
}
348350

349-
const useTrigger = isTruthy(env.TRIGGER_DEV_ENABLED)
351+
// Enterprise users always execute directly, others check TRIGGER_DEV_ENABLED env
352+
// Note: isEnterprise was already determined during rate limiting phase
353+
const useTrigger = !isEnterprise && isTruthy(env.TRIGGER_DEV_ENABLED)
350354

351355
if (useTrigger) {
352356
const handle = await tasks.trigger('webhook-execution', payload)
@@ -358,8 +362,9 @@ export async function POST(
358362
void executeWebhookJob(payload).catch((error) => {
359363
logger.error(`[${requestId}] Direct webhook execution failed`, error)
360364
})
365+
const reason = isEnterprise ? 'Enterprise plan' : 'Trigger.dev disabled'
361366
logger.info(
362-
`[${requestId}] Queued direct webhook execution for ${foundWebhook.provider} webhook (Trigger.dev disabled)`
367+
`[${requestId}] Queued direct webhook execution for ${foundWebhook.provider} webhook (${reason})`
363368
)
364369
}
365370

0 commit comments

Comments
 (0)