-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AIM-402 Extract queue discovery logic, add background-jobs-common dis…
…coverer, check for registered metrics before attempting to register them.
- Loading branch information
Showing
6 changed files
with
125 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Redis } from 'ioredis' | ||
Check warning on line 1 in lib/plugins/bull-mq-metrics/queueDiscoverers.ts GitHub Actions / build (18.x)
Check warning on line 1 in lib/plugins/bull-mq-metrics/queueDiscoverers.ts GitHub Actions / build (20.x)
|
||
import { AbstractBackgroundJobProcessor } from '@lokalise/background-jobs-common' | ||
Check warning on line 2 in lib/plugins/bull-mq-metrics/queueDiscoverers.ts GitHub Actions / build (18.x)
Check warning on line 2 in lib/plugins/bull-mq-metrics/queueDiscoverers.ts GitHub Actions / build (20.x)
|
||
|
||
export type QueueDiscoverer = { | ||
discoverQueues: () => Promise<string[]> | ||
} | ||
|
||
export class RedisBasedQueueDiscoverer implements QueueDiscoverer { | ||
constructor(private readonly redis: Redis, private readonly queuesPrefix: string) {} | ||
|
||
async discoverQueues(): Promise<string[]> { | ||
const scanStream = this.redis.scanStream({ | ||
match: `${this.queuesPrefix}:*:meta`, | ||
}) | ||
|
||
const queues = new Set<string>() | ||
for await (const chunk of scanStream) { | ||
(chunk as string[]) | ||
.map((key) => key.split(':')[1]) | ||
.filter((value) => !!value) | ||
.forEach((queue) => queues.add(queue)) | ||
} | ||
|
||
return Array.from(queues).sort() | ||
} | ||
} | ||
|
||
export class BackgroundJobsBasedQueueDiscoverer implements QueueDiscoverer { | ||
constructor(private readonly redis: Redis) {} | ||
|
||
async discoverQueues(): Promise<string[]> { | ||
return await AbstractBackgroundJobProcessor.getActiveQueueIds(this.redis) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters