@@ -10,6 +10,7 @@ import {
10
10
WorkspaceInstance ,
11
11
WorkspaceTimeoutDuration ,
12
12
WORKSPACE_TIMEOUT_DEFAULT_LONG ,
13
+ WORKSPACE_TIMEOUT_DEFAULT_SHORT ,
13
14
} from "@gitpod/gitpod-protocol" ;
14
15
import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
15
16
import { inject , injectable } from "inversify" ;
@@ -83,20 +84,28 @@ export class EntitlementServiceImpl implements EntitlementService {
83
84
}
84
85
85
86
async getDefaultWorkspaceTimeout ( user : User , date : Date = new Date ( ) ) : Promise < WorkspaceTimeoutDuration > {
87
+ let userWorkspaceTimeout : WorkspaceTimeoutDuration | undefined ;
88
+ try {
89
+ userWorkspaceTimeout = WorkspaceTimeoutDuration . validate ( user . additionalData ?. workspaceTimeout || "" ) ;
90
+ } catch ( e ) { }
91
+ let defaultWorkspaceTimeout : WorkspaceTimeoutDuration = WORKSPACE_TIMEOUT_DEFAULT_SHORT ;
86
92
try {
87
93
const billingMode = await this . billingModes . getBillingModeForUser ( user , date ) ;
88
94
switch ( billingMode . mode ) {
89
95
case "none" :
90
- return this . license . getDefaultWorkspaceTimeout ( user , date ) ;
96
+ defaultWorkspaceTimeout = await this . license . getDefaultWorkspaceTimeout ( user , date ) ;
91
97
case "chargebee" :
92
- return this . chargebee . getDefaultWorkspaceTimeout ( user , date ) ;
98
+ defaultWorkspaceTimeout = await this . chargebee . getDefaultWorkspaceTimeout ( user , date ) ;
93
99
case "usage-based" :
94
- return this . ubp . getDefaultWorkspaceTimeout ( user , date ) ;
100
+ defaultWorkspaceTimeout = await this . ubp . getDefaultWorkspaceTimeout ( user , date ) ;
95
101
}
96
102
} catch ( err ) {
97
103
log . error ( { userId : user . id } , "EntitlementService error: getDefaultWorkspaceTimeout" , err ) ;
98
- return WORKSPACE_TIMEOUT_DEFAULT_LONG ;
104
+ defaultWorkspaceTimeout = WORKSPACE_TIMEOUT_DEFAULT_LONG ;
99
105
}
106
+ return userWorkspaceTimeout && defaultWorkspaceTimeout == WORKSPACE_TIMEOUT_DEFAULT_LONG
107
+ ? userWorkspaceTimeout
108
+ : defaultWorkspaceTimeout ;
100
109
}
101
110
102
111
async userGetsMoreResources ( user : User , date : Date = new Date ( ) ) : Promise < boolean > {
0 commit comments