Fix subscription cross tenant issue (#16670)

As title
This commit is contained in:
martmull
2025-12-18 15:22:17 +01:00
committed by GitHub
parent c36bb8f3a1
commit 52cf3775b3
13 changed files with 178 additions and 105 deletions
@@ -0,0 +1,50 @@
import { Injectable } from '@nestjs/common';
import { SubscriptionChannel } from 'src/engine/subscriptions/enums/subscription-channel.enum';
import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-client.service';
@Injectable()
export class SubscriptionService {
constructor(private readonly redisClient: RedisClientService) {}
private getSubscriptionChannel({
channel,
workspaceId,
}: {
channel: SubscriptionChannel;
workspaceId: string;
}) {
return `${channel}:${workspaceId}`;
}
async subscribe({
channel,
workspaceId,
}: {
channel: SubscriptionChannel;
workspaceId: string;
}) {
const client = this.redisClient.getPubSubClient();
return client.asyncIterator(
this.getSubscriptionChannel({ channel, workspaceId }),
);
}
async publish<T>({
channel,
payload,
workspaceId,
}: {
channel: SubscriptionChannel;
payload: T;
workspaceId: string;
}): Promise<void> {
const client = this.redisClient.getPubSubClient();
await client.publish(
this.getSubscriptionChannel({ channel, workspaceId }),
payload,
);
}
}