Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 14 additions & 14 deletions apps/webapp/app/services/platform.v3.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export async function getCurrentPlan(orgId: string) {
firstDayOfNextMonth.setUTCHours(0, 0, 0, 0);

if (!result.success) {
logger.error("Error getting current plan", { orgId, error: result.error });
logger.error("Error getting current plan - no success", { orgId, error: result.error });
return undefined;
}

Expand All @@ -221,7 +221,7 @@ export async function getCurrentPlan(orgId: string) {

return { ...result, usage };
} catch (e) {
logger.error("Error getting current plan", { orgId, error: e });
logger.error("Error getting current plan - caught error", { orgId, error: e });
return undefined;
}
}
Expand All @@ -232,13 +232,13 @@ export async function getLimits(orgId: string) {
try {
const result = await client.currentPlan(orgId);
if (!result.success) {
logger.error("Error getting limits", { orgId, error: result.error });
logger.error("Error getting limits - no success", { orgId, error: result.error });
return undefined;
}

return result.v3Subscription?.plan?.limits;
} catch (e) {
logger.error("Error getting limits", { orgId, error: e });
logger.error("Error getting limits - caught error", { orgId, error: e });
return undefined;
}
}
Expand Down Expand Up @@ -279,12 +279,12 @@ export async function getPlans() {
try {
const result = await client.plans();
if (!result.success) {
logger.error("Error getting plans", { error: result.error });
logger.error("Error getting plans - no success", { error: result.error });
return undefined;
}
return result;
} catch (e) {
logger.error("Error getting plans", { error: e });
logger.error("Error getting plans - caught error", { error: e });
return undefined;
}
}
Expand Down Expand Up @@ -362,12 +362,12 @@ export async function getUsage(organizationId: string, { from, to }: { from: Dat
try {
const result = await client.usage(organizationId, { from, to });
if (!result.success) {
logger.error("Error getting usage", { error: result.error });
logger.error("Error getting usage - no success", { error: result.error });
return undefined;
}
return result;
} catch (e) {
logger.error("Error getting usage", { error: e });
logger.error("Error getting usage - caught error", { error: e });
return undefined;
}
}
Expand Down Expand Up @@ -396,12 +396,12 @@ export async function getUsageSeries(organizationId: string, params: UsageSeries
try {
const result = await client.usageSeries(organizationId, params);
if (!result.success) {
logger.error("Error getting usage series", { error: result.error });
logger.error("Error getting usage series - no success", { error: result.error });
return undefined;
}
return result;
} catch (e) {
logger.error("Error getting usage series", { error: e });
logger.error("Error getting usage series - caught error", { error: e });
return undefined;
}
}
Expand All @@ -420,12 +420,12 @@ export async function reportInvocationUsage(
additionalData,
});
if (!result.success) {
logger.error("Error reporting invocation", { error: result.error });
logger.error("Error reporting invocation - no success", { error: result.error });
return undefined;
}
return result;
} catch (e) {
logger.error("Error reporting invocation", { error: e });
logger.error("Error reporting invocation - caught error", { error: e });
return undefined;
}
}
Expand All @@ -448,14 +448,14 @@ export async function getEntitlement(
try {
const result = await client.getEntitlement(organizationId);
if (!result.success) {
logger.error("Error getting entitlement", { error: result.error });
logger.error("Error getting entitlement - no success", { error: result.error });
return {
hasAccess: true as const,
};
}
return result;
} catch (e) {
logger.error("Error getting entitlement", { error: e });
logger.error("Error getting entitlement - caught error", { error: e });
return {
hasAccess: true as const,
};
Expand Down
21 changes: 18 additions & 3 deletions apps/webapp/app/v3/runEngine.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defaultMachine, getCurrentPlan } from "~/services/platform.v3.server";
import { singleton } from "~/utils/singleton";
import { allMachines } from "./machinePresets.server";
import { meter, tracer } from "./tracer.server";
import { logger } from "~/services/logger.server";

export const engine = singleton("RunEngine", createRunEngine);

Expand Down Expand Up @@ -120,23 +121,37 @@ function createRunEngine() {
getCurrentPlan: async (orgId: string) => {
const plan = await getCurrentPlan(orgId);

// This only happens when there's no billing service running or on errors
if (!plan) {
logger.warn("engine.getCurrentPlan: no plan", { orgId });
return {
isPaying: false,
type: "free",
isPaying: true,
type: "paid", // default to paid
};
}

// This shouldn't happen
if (!plan.v3Subscription) {
logger.warn("engine.getCurrentPlan: no v3 subscription", { orgId });
return {
isPaying: false,
type: "free",
};
}

// Neither should this
if (!plan.v3Subscription.plan) {
logger.warn("engine.getCurrentPlan: no v3 subscription plan", { orgId });
return {
isPaying: plan.v3Subscription.isPaying,
type: plan.v3Subscription.isPaying ? "paid" : "free",
};
}

// This is the normal case when the billing service is running
return {
isPaying: plan.v3Subscription.isPaying,
type: plan.v3Subscription.plan?.type ?? "free",
type: plan.v3Subscription.plan.type,
};
},
},
Expand Down