Skip to content

Commit 9223caa

Browse files
authored
chore: fix autoscaling for team plan users (#1021)
We were autoscaling everyone's integrations
1 parent 6c56e30 commit 9223caa

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/core/src/services/mcpServers/autoScaleService.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SubscriptionPlan } from '../../plans'
66
import { autoScaleInactiveServers } from './autoScaleService'
77
import { createWorkspace, createMcpServer } from '../../tests/factories'
88
import { setupQueues } from '../../jobs'
9+
import { workspaces } from '../../schema'
910

1011
vi.mock('../../jobs', () => ({
1112
setupQueues: vi.fn(),
@@ -87,10 +88,18 @@ describe('autoScaleInactiveServers', () => {
8788
it('should not enqueue jobs for servers on non-hobby plans', async () => {
8889
// Create a workspace with a team plan
8990
const { workspace } = await createWorkspace()
91+
92+
// Create a team subscription
93+
const currentSubscription = await database
94+
.insert(subscriptions)
95+
.values({ workspaceId: workspace.id, plan: SubscriptionPlan.TeamV1 })
96+
.returning()
97+
98+
// Assing the subscription to the workspace
9099
await database
91-
.update(subscriptions)
92-
.set({ plan: SubscriptionPlan.TeamV1 })
93-
.where(eq(subscriptions.workspaceId, workspace.id))
100+
.update(workspaces)
101+
.set({ currentSubscriptionId: currentSubscription[0]!.id })
102+
.where(eq(workspaces.id, workspace.id))
94103

95104
// Create an inactive MCP server
96105
await createMcpServer({

packages/core/src/services/mcpServers/autoScaleService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { database } from '../../client'
55
import { and, eq, lt, inArray, gt } from 'drizzle-orm'
66
import { SubscriptionPlan } from '../../plans'
77
import { setupQueues } from '../../jobs'
8+
import { workspaces } from '../../schema'
89

910
const INACTIVITY_THRESHOLD_MINUTES = 10
1011
const SCALE_DOWN_REPLICAS = 0
@@ -22,9 +23,10 @@ export async function autoScaleInactiveServers(db = database) {
2223
const inactiveServers = await db
2324
.select({ id: mcpServers.id })
2425
.from(mcpServers)
26+
.innerJoin(workspaces, eq(mcpServers.workspaceId, workspaces.id))
2527
.innerJoin(
2628
subscriptions,
27-
eq(mcpServers.workspaceId, subscriptions.workspaceId),
29+
eq(workspaces.currentSubscriptionId, subscriptions.id),
2830
)
2931
.where(
3032
and(

0 commit comments

Comments
 (0)