Skip to content
Merged
2 changes: 1 addition & 1 deletion components/server/leeway.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the GNU Affero General Public License (AGPL).
# See License.AGPL.txt in the project root for license information.

FROM node:18.17.1-slim as builder
FROM node:18.17.1-slim AS builder

# Install Python, make, gcc and g++ for node-gyp
RUN apt-get update && \
Expand Down
7 changes: 6 additions & 1 deletion components/server/src/billing/entitlement-service-ubp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class EntitlementServiceUBP implements EntitlementService {
? Math.min(planAllowance, maxParallelRunningWorkspaces)
: planAllowance;

const current = (await runningInstances).filter((i) => i.status.phase !== "preparing").length;
const current = await getRunningInstancesCount(runningInstances);
if (current >= max) {
return {
current,
Expand Down Expand Up @@ -143,3 +143,8 @@ export class EntitlementServiceUBP implements EntitlementService {
return hasPaidPlan ? "paid" : "free";
}
}

export const getRunningInstancesCount = async (instancesPromise: Promise<WorkspaceInstance[]>): Promise<number> => {
const instances = await instancesPromise;
return instances.filter((i) => i.status.phase !== "preparing").length;
};
4 changes: 2 additions & 2 deletions components/server/src/billing/entitlement-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
import { BillingTier } from "@gitpod/gitpod-protocol/lib/protocol";
import { inject, injectable } from "inversify";
import { BillingModes } from "./billing-mode";
import { EntitlementServiceUBP, LazyOrganizationService } from "./entitlement-service-ubp";
import { EntitlementServiceUBP, getRunningInstancesCount, LazyOrganizationService } from "./entitlement-service-ubp";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";

export interface MayStartWorkspaceResult {
Expand Down Expand Up @@ -123,7 +123,7 @@ export class EntitlementServiceImpl implements EntitlementService {
// we use || here because the default value is 0 and we want to use the default limit if the organization limit is not set
const maxParallelRunningWorkspaces =
organizationSettings.maxParallelRunningWorkspaces || MAX_PARALLEL_WORKSPACES_PAID;
const current = (await runningInstances).filter((i) => i.status.phase !== "preparing").length;
const current = await getRunningInstancesCount(runningInstances);
if (current >= maxParallelRunningWorkspaces) {
return {
hitParallelWorkspaceLimit: {
Expand Down
Loading