Skip to content

Commit f93ba59

Browse files
committed
fix invalidate circular dep
1 parent 2ce9e6a commit f93ba59

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

apps/webapp/app/routes/resources.orgs.$organizationSlug.select-plan.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { redirectWithErrorMessage } from "~/models/message.server";
4242
import { logger } from "~/services/logger.server";
4343
import { setPlan } from "~/services/platform.v3.server";
4444
import { requireUser } from "~/services/session.server";
45+
import { engine } from "~/v3/runEngine.server";
4546
import { cn } from "~/utils/cn";
4647
import { sendToPlain } from "~/utils/plain.server";
4748

@@ -152,7 +153,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
152153
}
153154
}
154155

155-
return setPlan(organization, request, form.callerPath, payload);
156+
return setPlan(organization, request, form.callerPath, payload, {
157+
invalidateBillingCache: engine.invalidateBillingCache.bind(engine),
158+
});
156159
}
157160

158161
const pricingDefinitions = {

apps/webapp/app/services/platform.v3.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { logger } from "~/services/logger.server";
2121
import { newProjectPath, organizationBillingPath } from "~/utils/pathBuilder";
2222
import { singleton } from "~/utils/singleton";
2323
import { RedisCacheStore } from "./unkey/redisCacheStore.server";
24-
import { engine } from "~/v3/runEngine.server";
2524
import { existsSync, readFileSync } from "node:fs";
2625
import { z } from "zod";
2726
import { MachinePresetName } from "@trigger.dev/core/v3";
@@ -286,7 +285,8 @@ export async function setPlan(
286285
organization: { id: string; slug: string },
287286
request: Request,
288287
callerPath: string,
289-
plan: SetPlanBody
288+
plan: SetPlanBody,
289+
opts?: { invalidateBillingCache?: (orgId: string) => void }
290290
) {
291291
if (!client) {
292292
throw redirectWithErrorMessage(callerPath, request, "Error setting plan");
@@ -310,7 +310,7 @@ export async function setPlan(
310310
case "free_connected": {
311311
if (result.accepted) {
312312
// Invalidate billing cache since plan changed
313-
engine.invalidateBillingCache(organization.id);
313+
opts?.invalidateBillingCache?.(organization.id);
314314
return redirect(newProjectPath(organization, "You're on the Free plan."));
315315
} else {
316316
return redirectWithErrorMessage(
@@ -325,7 +325,7 @@ export async function setPlan(
325325
}
326326
case "updated_subscription": {
327327
// Invalidate billing cache since subscription changed
328-
engine.invalidateBillingCache(organization.id);
328+
opts?.invalidateBillingCache?.(organization.id);
329329
return redirectWithSuccessMessage(
330330
callerPath,
331331
request,
@@ -334,7 +334,7 @@ export async function setPlan(
334334
}
335335
case "canceled_subscription": {
336336
// Invalidate billing cache since subscription was canceled
337-
engine.invalidateBillingCache(organization.id);
337+
opts?.invalidateBillingCache?.(organization.id);
338338
return redirectWithSuccessMessage(callerPath, request, "Subscription canceled.");
339339
}
340340
}

0 commit comments

Comments
 (0)