Skip to content

Commit

Permalink
Clean up and add CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed May 21, 2024
1 parent 0fbb5ae commit 92ddc45
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/bullmq.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions bullmq/src/bull-mq-metrics-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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]
Expand Down
9 changes: 5 additions & 4 deletions bullmq/test/bull-mq-metrics-collector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ 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(() => {
collector.redis.quit()
})

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')

Expand Down

0 comments on commit 92ddc45

Please sign in to comment.