@@ -28,7 +28,6 @@ import {
28
28
WorkspaceTimeoutValues ,
29
29
SetWorkspaceTimeoutResult ,
30
30
WorkspaceContext ,
31
- CreateWorkspaceMode ,
32
31
WorkspaceCreationResult ,
33
32
PrebuiltWorkspaceContext ,
34
33
CommitContext ,
@@ -976,7 +975,8 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
976
975
parentCtx : TraceContext ,
977
976
user : User ,
978
977
context : WorkspaceContext ,
979
- mode : CreateWorkspaceMode ,
978
+ ignoreRunningPrebuild ?: boolean ,
979
+ allowUsingPreviousPrebuilds ?: boolean ,
980
980
) : Promise < WorkspaceCreationResult | PrebuiltWorkspaceContext | undefined > {
981
981
const ctx = TraceContext . childContext ( "findPrebuiltWorkspace" , parentCtx ) ;
982
982
try {
@@ -989,29 +989,38 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
989
989
const logCtx : LogContext = { userId : user . id } ;
990
990
const cloneUrl = context . repository . cloneUrl ;
991
991
let prebuiltWorkspace : PrebuiltWorkspace | undefined ;
992
+ const logPayload = {
993
+ allowUsingPreviousPrebuilds,
994
+ ignoreRunningPrebuild,
995
+ cloneUrl,
996
+ commit : commitSHAs ,
997
+ prebuiltWorkspace,
998
+ } ;
992
999
if ( OpenPrebuildContext . is ( context ) ) {
993
1000
prebuiltWorkspace = await this . workspaceDb . trace ( ctx ) . findPrebuildByID ( context . openPrebuildID ) ;
994
- if ( prebuiltWorkspace ?. cloneURL !== cloneUrl ) {
1001
+ if (
1002
+ prebuiltWorkspace ?. cloneURL !== cloneUrl &&
1003
+ ( ignoreRunningPrebuild || prebuiltWorkspace ?. state === "available" )
1004
+ ) {
995
1005
// prevent users from opening arbitrary prebuilds this way - they must match the clone URL so that the resource guards are correct.
996
1006
return ;
997
1007
}
998
1008
} else {
999
- prebuiltWorkspace = await this . workspaceDb
1000
- . trace ( ctx )
1001
- . findPrebuiltWorkspaceByCommit ( cloneUrl , commitSHAs ) ;
1002
- }
1003
-
1004
- const logPayload = { mode, cloneUrl, commit : commitSHAs , prebuiltWorkspace } ;
1005
- log . debug ( logCtx , "Looking for prebuilt workspace: " , logPayload ) ;
1006
- if ( prebuiltWorkspace ?. state !== "available" && mode === CreateWorkspaceMode . UseLastSuccessfulPrebuild ) {
1007
- const { config } = await this . configProvider . fetchConfig ( { } , user , context ) ;
1008
- const history = await this . incrementalPrebuildsService . getCommitHistoryForContext ( context , user ) ;
1009
- prebuiltWorkspace = await this . incrementalPrebuildsService . findGoodBaseForIncrementalBuild (
1010
- context ,
1011
- config ,
1012
- history ,
1013
- user ,
1014
- ) ;
1009
+ log . debug ( logCtx , "Looking for prebuilt workspace: " , logPayload ) ;
1010
+ if ( ! allowUsingPreviousPrebuilds ) {
1011
+ prebuiltWorkspace = await this . workspaceDb
1012
+ . trace ( ctx )
1013
+ . findPrebuiltWorkspaceByCommit ( cloneUrl , commitSHAs ) ;
1014
+ } else {
1015
+ const { config } = await this . configProvider . fetchConfig ( { } , user , context ) ;
1016
+ const history = await this . incrementalPrebuildsService . getCommitHistoryForContext ( context , user ) ;
1017
+ prebuiltWorkspace = await this . incrementalPrebuildsService . findGoodBaseForIncrementalBuild (
1018
+ context ,
1019
+ config ,
1020
+ history ,
1021
+ user ,
1022
+ ) ;
1023
+ }
1015
1024
}
1016
1025
if ( ! prebuiltWorkspace ) {
1017
1026
return ;
@@ -1026,13 +1035,9 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
1026
1035
} ;
1027
1036
return result ;
1028
1037
} else if ( prebuiltWorkspace . state === "queued" || prebuiltWorkspace . state === "building" ) {
1029
- if ( mode === CreateWorkspaceMode . ForceNew ) {
1038
+ if ( ignoreRunningPrebuild ) {
1030
1039
// in force mode we ignore running prebuilds as we want to start a workspace as quickly as we can.
1031
1040
return ;
1032
- // TODO(janx): Fall back to parent prebuild instead, if it's available:
1033
- // const buildWorkspace = await this.workspaceDb.trace({span}).findById(prebuiltWorkspace.buildWorkspaceId);
1034
- // const parentPrebuild = await this.workspaceDb.trace({span}).findPrebuildByID(buildWorkspace.basedOnPrebuildId);
1035
- // Also, make sure to initialize it by both printing the parent prebuild logs AND re-runnnig the before/init/prebuild tasks.
1036
1041
}
1037
1042
1038
1043
const workspaceID = prebuiltWorkspace . buildWorkspaceId ;
@@ -1097,36 +1102,34 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
1097
1102
1098
1103
const inSameCluster = wsi . region === this . config . installationShortname ;
1099
1104
if ( ! inSameCluster ) {
1100
- if ( mode === CreateWorkspaceMode . UsePrebuild ) {
1101
- /* We need to wait for this prebuild to finish before we return from here.
1102
- * This creation mode is meant to be used once we have gone through default mode, have confirmation from the
1103
- * message bus that the prebuild is done, and now only have to wait for dbsync to come through. Thus,
1104
- * in this mode we'll poll the database until the prebuild is ready (or we time out).
1105
- *
1106
- * Note: This polling mechanism only makes sense if the prebuild runs in cluster different from ours.
1107
- * Otherwise there's no dbsync inbetween that we might have to wait for.
1108
- *
1109
- * DB sync interval is 2 seconds at the moment, we wait ten "ticks" for the data to be synchronized.
1110
- */
1111
- const finishedPrebuiltWorkspace = await this . pollDatabaseUntilPrebuildIsAvailable (
1112
- ctx ,
1113
- prebuiltWorkspace . id ,
1114
- 20000 ,
1105
+ /* We need to wait for this prebuild to finish before we return from here.
1106
+ * This creation mode is meant to be used once we have gone through default mode, have confirmation from the
1107
+ * message bus that the prebuild is done, and now only have to wait for dbsync to come through. Thus,
1108
+ * in this mode we'll poll the database until the prebuild is ready (or we time out).
1109
+ *
1110
+ * Note: This polling mechanism only makes sense if the prebuild runs in cluster different from ours.
1111
+ * Otherwise there's no dbsync inbetween that we might have to wait for.
1112
+ *
1113
+ * DB sync interval is 2 seconds at the moment, we wait ten "ticks" for the data to be synchronized.
1114
+ */
1115
+ const finishedPrebuiltWorkspace = await this . pollDatabaseUntilPrebuildIsAvailable (
1116
+ ctx ,
1117
+ prebuiltWorkspace . id ,
1118
+ 20000 ,
1119
+ ) ;
1120
+ if ( ! finishedPrebuiltWorkspace ) {
1121
+ log . warn (
1122
+ logCtx ,
1123
+ "did not find a finished prebuild in the database despite waiting long enough after msgbus confirmed that the prebuild had finished" ,
1124
+ logPayload ,
1115
1125
) ;
1116
- if ( ! finishedPrebuiltWorkspace ) {
1117
- log . warn (
1118
- logCtx ,
1119
- "did not find a finished prebuild in the database despite waiting long enough after msgbus confirmed that the prebuild had finished" ,
1120
- logPayload ,
1121
- ) ;
1122
- return ;
1123
- } else {
1124
- return {
1125
- title : context . title ,
1126
- originalContext : context ,
1127
- prebuiltWorkspace : finishedPrebuiltWorkspace ,
1128
- } as PrebuiltWorkspaceContext ;
1129
- }
1126
+ return ;
1127
+ } else {
1128
+ return {
1129
+ title : context . title ,
1130
+ originalContext : context ,
1131
+ prebuiltWorkspace : finishedPrebuiltWorkspace ,
1132
+ } as PrebuiltWorkspaceContext ;
1130
1133
}
1131
1134
}
1132
1135
0 commit comments