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