Skip to content

Commit 8862678

Browse files
committed
feat(webapp): seed default billing alerts on organization creation
1 parent 92d1ae4 commit 8862678

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

apps/webapp/app/models/organization.server.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ import type {
66
RuntimeEnvironment,
77
User,
88
} from "@trigger.dev/database";
9+
import { tryCatch } from "@trigger.dev/core";
910
import { customAlphabet } from "nanoid";
1011
import { generate } from "random-words";
1112
import slug from "slug";
1213
import { $replica, prisma, type PrismaClientOrTransaction } from "~/db.server";
1314
import { env } from "~/env.server";
1415
import { featuresForUrl } from "~/features.server";
1516
import { createApiKeyForEnv, createPkApiKeyForEnv, envSlug } from "./api-key.server";
16-
import { getDefaultEnvironmentConcurrencyLimit } from "~/services/platform.v3.server";
17+
import {
18+
getDefaultEnvironmentConcurrencyLimit,
19+
isBillingConfigured,
20+
setBillingAlert,
21+
} from "~/services/platform.v3.server";
22+
import { buildDefaultBillingAlerts } from "~/services/billingAlertsDefaults.server";
1723
import { enqueueAttioWorkspaceSync } from "~/services/attio.server";
24+
import { logger } from "~/services/logger.server";
1825
import {
1926
applyBillingLimitPauseAfterEnvCreate,
2027
getInitialEnvPauseStateForBillingLimit,
@@ -122,9 +129,26 @@ export async function createOrganization(
122129
adminUserId: userId,
123130
});
124131

132+
void seedDefaultBillingAlerts(organization.id);
133+
125134
return { ...organization };
126135
}
127136

137+
/** Seed default billing alerts for a new org. Never blocks/fails org creation. */
138+
async function seedDefaultBillingAlerts(organizationId: string): Promise<void> {
139+
if (!isBillingConfigured()) {
140+
return;
141+
}
142+
143+
const [error] = await tryCatch(setBillingAlert(organizationId, buildDefaultBillingAlerts()));
144+
if (error) {
145+
logger.warn("Failed to seed default billing alerts for new org", {
146+
organizationId,
147+
error: error instanceof Error ? error.message : error,
148+
});
149+
}
150+
}
151+
128152
export async function createEnvironment({
129153
organization,
130154
project,

0 commit comments

Comments
 (0)