Skip to content

Commit

Permalink
fix: only use active consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley2058 committed Jan 21, 2025
1 parent efbb11f commit d0acec0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,13 @@ export class Worker {
}

async checkAndRecoverOrphanStreams () {
const consumers = (
await this.client.redis.xInfoConsumers(
this.client.redisWorkerStreamName,
this.client.redisWorkerGroupName
)
).map(({ name }) => name)
const rawConsumers = await this.client.redis.xInfoConsumers(
this.client.redisWorkerStreamName,
this.client.redisWorkerGroupName
)
const consumers = rawConsumers
.filter((c) => c.pending > 0 || c.inactive < this.client.redisWorkerTimeout)
.map(({ name }) => name)
const leader = consumers.sort()[0]
if (this.client.consumername !== leader) return

Expand Down

0 comments on commit d0acec0

Please sign in to comment.