@@ -22,10 +22,14 @@ import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/expe
22
22
import { Attributes } from "@gitpod/gitpod-protocol/lib/experiments/types" ;
23
23
import { reportRedisUpdateCompleted , reportRedisUpdateReceived } from "../prometheus-metrics" ;
24
24
import { Redis } from "ioredis" ;
25
+ import { WorkspaceDB } from "@gitpod/gitpod-db/lib" ;
25
26
26
27
@injectable ( )
27
28
export class RedisSubscriber implements LocalMessageBroker {
28
- constructor ( @inject ( Redis ) private readonly redis : Redis ) { }
29
+ constructor (
30
+ @inject ( Redis ) private readonly redis : Redis ,
31
+ @inject ( WorkspaceDB ) private readonly workspaceDB : WorkspaceDB ,
32
+ ) { }
29
33
30
34
protected workspaceInstanceUpdateListeners : Map < string , WorkspaceInstanceUpdateListener [ ] > = new Map ( ) ;
31
35
@@ -73,6 +77,33 @@ export class RedisSubscriber implements LocalMessageBroker {
73
77
74
78
private async onInstanceUpdate ( update : RedisWorkspaceInstanceUpdate ) : Promise < void > {
75
79
log . debug ( "[redis] Received instance update" , { update } ) ;
80
+
81
+ if ( ! update . ownerID || ! update . instanceID ) {
82
+ return ;
83
+ }
84
+
85
+ const listeners = this . workspaceInstanceUpdateListeners . get ( update . ownerID ) || [ ] ;
86
+ if ( listeners . length === 0 ) {
87
+ return ;
88
+ }
89
+
90
+ const ctx = { } ;
91
+ const instance = await this . workspaceDB . findInstanceById ( update . instanceID ) ;
92
+ if ( ! instance ) {
93
+ return ;
94
+ }
95
+
96
+ for ( const l of listeners ) {
97
+ try {
98
+ l ( ctx , instance ) ;
99
+ } catch ( err ) {
100
+ log . error (
101
+ { userId : update . ownerID , instanceId : instance . id , workspaceId : update . workspaceID } ,
102
+ "Failed to broadcast workspace instance update." ,
103
+ err ,
104
+ ) ;
105
+ }
106
+ }
76
107
}
77
108
78
109
async stop ( ) {
0 commit comments