Remove site kick

This commit is contained in:
Owen
2026-02-09 17:23:48 -08:00
parent 7d8185e0ee
commit 431e6ffaae
11 changed files with 61 additions and 173 deletions

View File

@@ -8,77 +8,60 @@ export type LimitSet = Partial<{
}>;
export const sandboxLimitSet: LimitSet = {
[FeatureId.SITES]: { value: 1, description: "Sandbox limit" }, // 1 site up for 2 days
[FeatureId.USERS]: { value: 1, description: "Sandbox limit" },
[FeatureId.EGRESS_DATA_MB]: { value: 1000, description: "Sandbox limit" }, // 1 GB
[FeatureId.SITES]: { value: 1, description: "Sandbox limit" },
[FeatureId.DOMAINS]: { value: 0, description: "Sandbox limit" },
[FeatureId.REMOTE_EXIT_NODES]: { value: 0, description: "Sandbox limit" }
[FeatureId.REMOTE_EXIT_NODES]: { value: 0, description: "Sandbox limit" },
};
export const freeLimitSet: LimitSet = {
[FeatureId.SITES]: { value: 3, description: "Free tier limit" }, // 1 site up for 32 days
[FeatureId.USERS]: { value: 3, description: "Free tier limit" },
[FeatureId.EGRESS_DATA_MB]: {
value: 25000,
description: "Free tier limit"
}, // 25 GB
[FeatureId.DOMAINS]: { value: 3, description: "Free tier limit" },
[FeatureId.REMOTE_EXIT_NODES]: { value: 0, description: "Free tier limit" }
[FeatureId.USERS]: { value: 5, description: "Starter limit" },
[FeatureId.SITES]: { value: 5, description: "Starter limit" },
[FeatureId.DOMAINS]: { value: 5, description: "Starter limit" },
[FeatureId.REMOTE_EXIT_NODES]: { value: 1, description: "Starter limit" },
};
export const homeLabLimitSet: LimitSet = {
[FeatureId.SITES]: { value: 3, description: "Home lab limit" }, // 1 site up for 32 days
[FeatureId.USERS]: { value: 3, description: "Home lab limit" },
[FeatureId.EGRESS_DATA_MB]: {
value: 25000,
description: "Home lab limit"
}, // 25 GB
[FeatureId.DOMAINS]: { value: 3, description: "Home lab limit" },
[FeatureId.REMOTE_EXIT_NODES]: { value: 1, description: "Home lab limit" }
export const tier1LimitSet: LimitSet = {
[FeatureId.USERS]: { value: 7, description: "Home limit" },
[FeatureId.SITES]: { value: 10, description: "Home limit" },
[FeatureId.DOMAINS]: { value: 10, description: "Home limit" },
[FeatureId.REMOTE_EXIT_NODES]: { value: 1, description: "Home limit" },
};
export const tier2LimitSet: LimitSet = {
[FeatureId.SITES]: {
value: 10,
description: "Starter limit"
}, // 50 sites up for 31 days
[FeatureId.USERS]: {
value: 150,
description: "Starter limit"
value: 100,
description: "Team limit"
},
[FeatureId.SITES]: {
value: 50,
description: "Team limit"
},
[FeatureId.EGRESS_DATA_MB]: {
value: 12000000,
description: "Starter limit"
}, // 12000 GB
[FeatureId.DOMAINS]: {
value: 250,
description: "Starter limit"
value: 50,
description: "Team limit"
},
[FeatureId.REMOTE_EXIT_NODES]: {
value: 5,
description: "Starter limit"
}
value: 3,
description: "Team limit"
},
};
export const tier3LimitSet: LimitSet = {
[FeatureId.SITES]: {
value: 10,
description: "Scale limit"
}, // 50 sites up for 31 days
[FeatureId.USERS]: {
value: 150,
description: "Scale limit"
value: 500,
description: "Business limit"
},
[FeatureId.EGRESS_DATA_MB]: {
value: 12000000,
description: "Scale limit"
}, // 12000 GB
[FeatureId.DOMAINS]: {
[FeatureId.SITES]: {
value: 250,
description: "Scale limit"
description: "Business limit"
},
[FeatureId.DOMAINS]: {
value: 100,
description: "Business limit"
},
[FeatureId.REMOTE_EXIT_NODES]: {
value: 5,
description: "Scale limit"
}
value: 20,
description: "Business limit"
},
};

View File

@@ -517,7 +517,6 @@ export class UsageService {
public async checkLimitSet(
orgId: string,
kickSites = false,
featureId?: FeatureId,
usage?: Usage,
trx: Transaction | typeof db = db
@@ -591,58 +590,6 @@ export class UsageService {
break; // Exit early if any limit is exceeded
}
}
// If any limits are exceeded, disconnect all sites for this organization
if (hasExceededLimits && kickSites) {
logger.warn(
`Disconnecting all sites for org ${orgId} due to exceeded limits`
);
// Get all sites for this organization
const orgSites = await trx
.select()
.from(sites)
.where(eq(sites.orgId, orgId));
// Mark all sites as offline and send termination messages
const siteUpdates = orgSites.map((site) => site.siteId);
if (siteUpdates.length > 0) {
// Send termination messages to newt sites
for (const site of orgSites) {
if (site.type === "newt") {
const [newt] = await trx
.select()
.from(newts)
.where(eq(newts.siteId, site.siteId))
.limit(1);
if (newt) {
const payload = {
type: `newt/wg/terminate`,
data: {
reason: "Usage limits exceeded"
}
};
// Don't await to prevent blocking
await sendToClient(newt.newtId, payload).catch(
(error: any) => {
logger.error(
`Failed to send termination message to newt ${newt.newtId}:`,
error
);
}
);
}
}
}
logger.info(
`Disconnected ${orgSites.length} sites for org ${orgId} due to exceeded limits`
);
}
}
} catch (error) {
logger.error(`Error checking limits for org ${orgId}:`, error);
}