From 92ddc4580a3afa70cb35855f47a68eb0ab8a42be Mon Sep 17 00:00:00 2001 From: Adam McCrea Date: Tue, 21 May 2024 12:53:14 -0400 Subject: [PATCH] Clean up and add CI workflow --- .github/workflows/bullmq.yml | 49 +++++++++++++++++++ bullmq/src/bull-mq-metrics-collector.js | 3 +- bullmq/test/bull-mq-metrics-collector.test.js | 9 ++-- 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/bullmq.yml diff --git a/.github/workflows/bullmq.yml b/.github/workflows/bullmq.yml new file mode 100644 index 0000000..b15b9e7 --- /dev/null +++ b/.github/workflows/bullmq.yml @@ -0,0 +1,49 @@ +name: BullMQ adapter tests + +on: + push: + branches: [main] + pull_request: {} + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + node-version: [18.x, 20.x] + bullmq-version: [4.x, 5.x] + + steps: + - uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + # We can't use `cache: npm` because setup-node doesn't support our monorepo setup + node-version: ${{ matrix.node-version }} + + - name: Cache node modules + uses: actions/cache@v2 + with: + path: '**/node_modules' + key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }} + + - name: Prepare local dependency + run: | + npm install + npm run build + npm link + working-directory: node-core + + - name: Install dependencies & link local dependency + run: | + npm install + npm install bullmq@${{ matrix.bullmq-version }} + npm link judoscale-node-core + working-directory: bullmq + + - name: Run tests + run: npm test + working-directory: bullmq diff --git a/bullmq/src/bull-mq-metrics-collector.js b/bullmq/src/bull-mq-metrics-collector.js index 84a9725..329b3ef 100644 --- a/bullmq/src/bull-mq-metrics-collector.js +++ b/bullmq/src/bull-mq-metrics-collector.js @@ -10,8 +10,6 @@ class BullMQMetricsCollector extends WorkerMetricsCollector { this.redis = new Redis({ connection: { url: redisUrl } }) this.queueNames = new Set() - - // TODO: do we need redis.quit() ?? } async collect() { @@ -33,6 +31,7 @@ class BullMQMetricsCollector extends WorkerMetricsCollector { async fetchQueueNames() { const redisKeys = [] let cursor = '0' + do { const reply = await this.redis.scan(cursor, 'MATCH', 'bull:*:id') cursor = reply[0] diff --git a/bullmq/test/bull-mq-metrics-collector.test.js b/bullmq/test/bull-mq-metrics-collector.test.js index 25d6c2f..d9aa42b 100644 --- a/bullmq/test/bull-mq-metrics-collector.test.js +++ b/bullmq/test/bull-mq-metrics-collector.test.js @@ -4,8 +4,12 @@ const BullMQMetricsCollector = require('../src/bull-mq-metrics-collector') describe('BullMQMetricsCollector', () => { let collector - beforeEach(() => { + beforeEach(async () => { collector = new BullMQMetricsCollector() + + // Clear all Bull information in Redis + const keys = await collector.redis.keys('bull:*') + if (keys.length) await collector.redis.del(keys) }) afterEach(() => { @@ -13,9 +17,6 @@ describe('BullMQMetricsCollector', () => { }) test('collects queue metrics', async () => { - const keys = await collector.redis.keys('bull:*') - if (keys.length) await collector.redis.del(keys) - const queue = new Queue('foo', { connection: collector.redis }) await queue.add('test-job')