Skip to content

Commit

Permalink
[server] consider unfinished prebuilds (#19152)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenefftinge authored Nov 28, 2023
1 parent 5fc4561 commit 1a68211
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions components/server/src/prebuilds/incremental-workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
WorkspaceImageSource,
} from "@gitpod/gitpod-protocol";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { WithCommitHistory } from "@gitpod/gitpod-protocol/lib/protocol";
import { PrebuiltWorkspaceState, WithCommitHistory } from "@gitpod/gitpod-protocol/lib/protocol";
import { WorkspaceDB } from "@gitpod/gitpod-db/lib";
import { Config } from "../config";
import { ConfigProvider } from "../workspace/config-provider";
Expand Down Expand Up @@ -74,6 +74,7 @@ export class IncrementalWorkspaceService {
history: WithCommitHistory,
user: User,
projectId: string,
includeUnfinishedPrebuilds?: boolean,
): Promise<PrebuiltWorkspace | undefined> {
if (!history.commitHistory || history.commitHistory.length < 1) {
return;
Expand All @@ -93,6 +94,7 @@ export class IncrementalWorkspaceService {
imageSource,
recentPrebuild.prebuild,
recentPrebuild.workspace,
includeUnfinishedPrebuilds,
)
) {
return recentPrebuild.prebuild;
Expand All @@ -107,6 +109,7 @@ export class IncrementalWorkspaceService {
imageSource: WorkspaceImageSource,
candidatePrebuild: PrebuiltWorkspace,
candidateWorkspace: Workspace,
includeUnfinishedPrebuilds?: boolean,
): boolean {
if (!history.commitHistory || history.commitHistory.length === 0) {
return false;
Expand All @@ -115,8 +118,13 @@ export class IncrementalWorkspaceService {
return false;
}

// we are only considering available prebuilds
if (candidatePrebuild.state !== "available") {
const acceptableStates: PrebuiltWorkspaceState[] = ["available"];
if (includeUnfinishedPrebuilds) {
acceptableStates.push("building");
acceptableStates.push("queued");
}

if (!acceptableStates.includes(candidatePrebuild.state)) {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion components/server/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class PrebuildManager {
const prebuildInterval = prebuildSettings.prebuildInterval;
if (!forcePrebuild && prebuildInterval > 0) {
const history = {
commitHistory: commitHistory?.slice(0, prebuildInterval),
commitHistory: commitHistory?.slice(0, prebuildInterval + 1),
additionalRepositoryCommitHistories: additionalRepositoryCommitHistories?.map((repoHist) => ({
cloneUrl: repoHist.cloneUrl,
commitHistory: repoHist.commitHistory.slice(0, prebuildInterval),
Expand All @@ -296,6 +296,7 @@ export class PrebuildManager {
history,
user,
project.id,
true,
);
if (prebuild) {
return { prebuildId: prebuild.id, wsid: prebuild.buildWorkspaceId, done: true };
Expand Down

0 comments on commit 1a68211

Please sign in to comment.