diff --git a/apps/webapp/app/services/events/ingestSendEvent.server.ts b/apps/webapp/app/services/events/ingestSendEvent.server.ts index e0eccc3d9..034fad971 100644 --- a/apps/webapp/app/services/events/ingestSendEvent.server.ts +++ b/apps/webapp/app/services/events/ingestSendEvent.server.ts @@ -60,6 +60,11 @@ export class IngestSendEvent { try { const deliverAt = this.#calculateDeliverAt(options); + if (!environment.organization.runsEnabled) { + logger.debug("IngestSendEvent: Runs are disabled for this organization", environment); + return; + } + return await $transaction(this.#prismaClient, async (tx) => { const externalAccount = options?.accountId ? await tx.externalAccount.upsert({ diff --git a/apps/webapp/app/services/runs/startRun.server.ts b/apps/webapp/app/services/runs/startRun.server.ts index 6d9f2ab03..6dfb0a5ba 100644 --- a/apps/webapp/app/services/runs/startRun.server.ts +++ b/apps/webapp/app/services/runs/startRun.server.ts @@ -8,6 +8,7 @@ import { $transaction, prisma } from "~/db.server"; import { workerQueue } from "../worker.server"; import { ResumeRunService } from "./resumeRun.server"; import { createHash } from "node:crypto"; +import { logger } from "../logger.server"; type FoundRun = NonNullable>>; type RunConnectionsByKey = Awaited>; @@ -36,6 +37,13 @@ export class StartRunService { } #runIsStartable(run: FoundRun) { + if (!run.organization.runsEnabled) { + logger.debug("StartRunService: Runs are disabled for this organization", { + organizationId: run.organization.id, + }); + return false; + } + const startableStatuses = ["PENDING", "WAITING_ON_CONNECTIONS"] as const; return startableStatuses.includes(run.status); } @@ -144,6 +152,7 @@ async function findRun(tx: PrismaClientOrTransaction, id: string) { include: { queue: true, environment: true, + organization: true, version: { include: { integrations: { diff --git a/apps/webapp/app/services/sources/handleHttpSource.server.ts b/apps/webapp/app/services/sources/handleHttpSource.server.ts index e68c845d4..612779b19 100644 --- a/apps/webapp/app/services/sources/handleHttpSource.server.ts +++ b/apps/webapp/app/services/sources/handleHttpSource.server.ts @@ -4,6 +4,7 @@ import { workerQueue } from "../worker.server"; import { requestUrl } from "~/utils/requestUrl.server"; import { RuntimeEnvironmentType } from "@trigger.dev/database"; import { createHttpSourceRequest } from "~/utils/createHttpSourceRequest"; +import { logger } from "../logger.server"; export class HandleHttpSourceService { #prismaClient: PrismaClient; @@ -19,6 +20,7 @@ export class HandleHttpSourceService { endpoint: true, environment: true, secretReference: true, + organization: true, }, }); @@ -30,6 +32,13 @@ export class HandleHttpSourceService { return { status: 200 }; } + if (!triggerSource.organization.runsEnabled) { + logger.debug("HandleHttpSourceService: Runs are disabled for this organization", { + organizationId: triggerSource.organization.id, + }); + return { status: 404 }; + } + if (!triggerSource.interactive) { const sourceRequest = await createHttpSourceRequest(request);