Skip to content

Commit

Permalink
test: add shared redis instances in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Feb 5, 2024
1 parent 4156a2a commit fb9a649
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
31 changes: 29 additions & 2 deletions example/bull.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express');
const IORedis = require('ioredis');
const path = require('path');
const Arena = require('../');
const Bull = require('bull');
Expand All @@ -8,7 +9,19 @@ const HTTP_SERVER_PORT = 4735;
const REDIS_SERVER_PORT = 6379;

async function main() {
const queue = new Bull('name_of_my_queue', {
const queueName1 = 'name_of_my_queue_1';
const connection = new IORedis({port: REDIS_SERVER_PORT});

const createClient = (type) => {
switch (type) {
case 'client':
return connection;
default:
return new IORedis({port: REDIS_SERVER_PORT});
}
};

const queue = new Bull(queueName1, {
redis: {
port: REDIS_SERVER_PORT,
},
Expand Down Expand Up @@ -42,7 +55,7 @@ async function main() {
queues: [
{
// Required for each queue definition.
name: 'name_of_my_queue',
name: queueName1,

// User-readable display name for the host. Required.
hostId: 'Queue Server 1',
Expand All @@ -55,6 +68,20 @@ async function main() {
port: REDIS_SERVER_PORT,
},
},
{
// Required for each queue definition.
name: 'name_of_my_queue_2',

// User-readable display name for the host. Required.
hostId: 'Queue Server 2',

// Queue type (Bull or Bee - default Bull).
type: 'bull',

redis: {
createClient,
},
},
],
customJsPath: 'http://localhost:4735/example.js',
},
Expand Down
8 changes: 4 additions & 4 deletions example/bullmq.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Arena = require('../');
const IORedis = require('ioredis');
const {Queue, Worker, FlowProducer} = require('bullmq');

// Select ports that are unlikely to be used by other services a developer might be running locally.
Expand All @@ -9,6 +10,8 @@ async function main() {
const queueName = 'name_of_my_queue';
const parentQueueName = 'name_of_my_parent_queue';

const connection = new IORedis({port: REDIS_SERVER_PORT});

const queue = new Queue(queueName, {
connection: {port: REDIS_SERVER_PORT},
});
Expand Down Expand Up @@ -87,10 +90,7 @@ async function main() {
// Queue type (Bull or Bullmq or Bee - default Bull).
type: 'bullmq',

redis: {
// host: 'localhost',
port: REDIS_SERVER_PORT,
},
redis: connection,
},
{
// Required for each queue definition.
Expand Down
3 changes: 0 additions & 3 deletions src/server/queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ class Queues {
queue = new Bee(name, options);
queue.IS_BEE = true;
} else if (isBullMQ) {
if (queueConfig.createClient)
options.createClient = queueConfig.createClient;

const {BullMQ} = this._config;
const {redis, ...rest} = options;
queue = new BullMQ(name, {
Expand Down

0 comments on commit fb9a649

Please sign in to comment.