@@ -324,23 +324,24 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
324
324
private async listenForPrebuildUpdates ( ) {
325
325
// 'registering for prebuild updates for all projects this user has access to
326
326
const projects = await this . getAccessibleProjects ( ) ;
327
- for ( const projectId of projects ) {
328
- this . disposables . push (
329
- this . localMessageBroker . listenForPrebuildUpdates (
330
- projectId ,
331
- ( ctx : TraceContext , update : PrebuildWithStatus ) =>
332
- TraceContext . withSpan (
333
- "forwardPrebuildUpdateToClient" ,
334
- ( ctx ) => {
335
- traceClientMetadata ( ctx , this . clientMetadata ) ;
336
- TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
337
-
338
- this . client ?. onPrebuildUpdate ( update ) ;
339
- } ,
340
- ctx ,
341
- ) ,
342
- ) ,
327
+
328
+ const handler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
329
+ TraceContext . withSpan (
330
+ "forwardPrebuildUpdateToClient" ,
331
+ ( ctx ) => {
332
+ traceClientMetadata ( ctx , this . clientMetadata ) ;
333
+ TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
334
+
335
+ this . client ?. onPrebuildUpdate ( update ) ;
336
+ } ,
337
+ ctx ,
343
338
) ;
339
+
340
+ for ( const projectId of projects ) {
341
+ this . disposables . pushAll ( [
342
+ this . localMessageBroker . listenForPrebuildUpdates ( projectId , handler ) ,
343
+ this . subscriber . listenForPrebuildUpdates ( projectId , handler ) ,
344
+ ] ) ;
344
345
}
345
346
346
347
// TODO(at) we need to keep the list of accessible project up to date
@@ -3088,22 +3089,21 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3088
3089
3089
3090
const project = await this . projectsService . createProject ( params , user ) ;
3090
3091
// update client registration for the logged in user
3091
- this . disposables . push (
3092
- this . localMessageBroker . listenForPrebuildUpdates (
3093
- project . id ,
3094
- ( ctx : TraceContext , update : PrebuildWithStatus ) =>
3095
- TraceContext . withSpan (
3096
- "forwardPrebuildUpdateToClient" ,
3097
- ( ctx ) => {
3098
- traceClientMetadata ( ctx , this . clientMetadata ) ;
3099
- TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
3100
-
3101
- this . client ?. onPrebuildUpdate ( update ) ;
3102
- } ,
3103
- ctx ,
3104
- ) ,
3105
- ) ,
3106
- ) ;
3092
+ const prebuildUpdateHandler = ( ctx : TraceContext , update : PrebuildWithStatus ) =>
3093
+ TraceContext . withSpan (
3094
+ "forwardPrebuildUpdateToClient" ,
3095
+ ( ctx ) => {
3096
+ traceClientMetadata ( ctx , this . clientMetadata ) ;
3097
+ TraceContext . setJsonRPCMetadata ( ctx , "onPrebuildUpdate" ) ;
3098
+
3099
+ this . client ?. onPrebuildUpdate ( update ) ;
3100
+ } ,
3101
+ ctx ,
3102
+ ) ;
3103
+ this . disposables . pushAll ( [
3104
+ this . localMessageBroker . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ,
3105
+ this . subscriber . listenForPrebuildUpdates ( project . id , prebuildUpdateHandler ) ,
3106
+ ] ) ;
3107
3107
3108
3108
return project ;
3109
3109
}
0 commit comments