( chatIds: string[] )
| 137 | * in a multi-pod deployment. |
| 138 | */ |
| 139 | export async function getChatStreamLockOwners( |
| 140 | chatIds: string[] |
| 141 | ): Promise<ChatStreamLockOwnersResult> { |
| 142 | const localOwnersByChatId = new Map<string, string>() |
| 143 | if (chatIds.length === 0) { |
| 144 | return { status: 'verified', ownersByChatId: localOwnersByChatId } |
| 145 | } |
| 146 | |
| 147 | for (const chatId of chatIds) { |
| 148 | const entry = pendingChatStreams.get(chatId) |
| 149 | if (entry?.streamId) localOwnersByChatId.set(chatId, entry.streamId) |
| 150 | } |
| 151 | |
| 152 | const redis = getRedisClient() |
| 153 | if (!redis) { |
| 154 | return { status: 'unknown', ownersByChatId: localOwnersByChatId } |
| 155 | } |
| 156 | |
| 157 | try { |
| 158 | const keys = chatIds.map(getChatStreamLockKey) |
| 159 | const values = await redis.mget(keys) |
| 160 | const redisOwnersByChatId = new Map<string, string>() |
| 161 | for (let i = 0; i < chatIds.length; i++) { |
| 162 | const owner = values[i] |
| 163 | if (owner) redisOwnersByChatId.set(chatIds[i], owner) |
| 164 | } |
| 165 | return { status: 'verified', ownersByChatId: redisOwnersByChatId } |
| 166 | } catch (error) { |
| 167 | logger.warn('Failed to load chat stream lock owners (batch)', { |
| 168 | count: chatIds.length, |
| 169 | error: toError(error).message, |
| 170 | }) |
| 171 | return { status: 'unknown', ownersByChatId: localOwnersByChatId } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | export async function releasePendingChatStream(chatId: string, streamId: string): Promise<void> { |
| 176 | try { |
no test coverage detected