From 5853b314a0b17ab14079fd7e06b9c4ed82d5ddc0 Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Thu, 31 Aug 2023 23:45:49 -0600 Subject: [PATCH] chore: use redis container for testing (#663) --- example/README.md | 19 +++++++++++++++++-- example/bee.js | 8 +------- example/bull.js | 8 +------- example/bullmq.js | 7 +------ example/bullmq_with_flows.js | 7 +------ example/docker-compose.yml | 7 +++++++ example/express.js | 7 +------ example/fastify.js | 7 +------ example/package.json | 5 +++-- 9 files changed, 33 insertions(+), 42 deletions(-) create mode 100644 example/docker-compose.yml diff --git a/example/README.md b/example/README.md index 6ed6dd00..aee225f2 100644 --- a/example/README.md +++ b/example/README.md @@ -1,11 +1,18 @@ ## Overview -This is a simple demonstration of how to run Arena and connect it to [Bee Queue](https://github.com/mixmaxhq/bee-queue) or [Bull Queue](https://github.com/OptimalBits/bull). +This is a simple demonstration of how to run Arena and connect it to [Bee Queue](https://github.com/mixmaxhq/bee-queue) or [Bull Queue](https://github.com/OptimalBits/bull) or [BullMQ](https://github.com/taskforcesh/bullmq). ## Requirements - Node >= 7.6 -- No other services running on ports 4735 or 4736 +- No other services running on ports 4735 or 6379 + +## Start Redis + +In case you don't have redis installed, there is a redis docker-compose for development purposes. + +- Before starting Redis, make sure you have [docker-compose](https://docs.docker.com/compose/install/) installed. +- Then execute `npm run dc:up` ## Install @@ -13,6 +20,14 @@ This is a simple demonstration of how to run Arena and connect it to [Bee Queue] ## Running +`npm run start:fastify` + +or + +`npm run start:express` + +or + `npm run start:bee` or diff --git a/example/bee.js b/example/bee.js index 8396db79..7f804726 100644 --- a/example/bee.js +++ b/example/bee.js @@ -1,17 +1,11 @@ const Arena = require('../'); const Bee = require('bee-queue'); -const RedisServer = require('redis-server'); // Select ports that are unlikely to be used by other services a developer might be running locally. const HTTP_SERVER_PORT = 4735; -const REDIS_SERVER_PORT = 4736; - -// Create a Redis server. This is only for convenience +const REDIS_SERVER_PORT = 6379; async function main() { - const server = new RedisServer(REDIS_SERVER_PORT); - await server.open(); - const queue = new Bee('name_of_my_queue', { activateDelayedJobs: true, redis: { diff --git a/example/bull.js b/example/bull.js index d9e09e22..0a630614 100644 --- a/example/bull.js +++ b/example/bull.js @@ -2,18 +2,12 @@ const express = require('express'); const path = require('path'); const Arena = require('../'); const Bull = require('bull'); -const RedisServer = require('redis-server'); // Select ports that are unlikely to be used by other services a developer might be running locally. const HTTP_SERVER_PORT = 4735; -const REDIS_SERVER_PORT = 4736; - -// Create a Redis server. This is only for convenience +const REDIS_SERVER_PORT = 6379; async function main() { - const server = new RedisServer(REDIS_SERVER_PORT); - await server.open(); - const queue = new Bull('name_of_my_queue', { redis: { port: REDIS_SERVER_PORT, diff --git a/example/bullmq.js b/example/bullmq.js index 1c1c438e..f1a2932d 100644 --- a/example/bullmq.js +++ b/example/bullmq.js @@ -1,16 +1,11 @@ const Arena = require('../'); const {Queue, Worker, FlowProducer} = require('bullmq'); -const RedisServer = require('redis-server'); // Select ports that are unlikely to be used by other services a developer might be running locally. const HTTP_SERVER_PORT = 4735; -const REDIS_SERVER_PORT = 4736; - -// Create a Redis server. This is only for convenience +const REDIS_SERVER_PORT = 6379; async function main() { - const server = new RedisServer(REDIS_SERVER_PORT); - await server.open(); const queueName = 'name_of_my_queue'; const parentQueueName = 'name_of_my_parent_queue'; diff --git a/example/bullmq_with_flows.js b/example/bullmq_with_flows.js index b69c2d11..0f549297 100644 --- a/example/bullmq_with_flows.js +++ b/example/bullmq_with_flows.js @@ -1,16 +1,11 @@ const Arena = require('../'); const {Queue, Worker, FlowProducer} = require('bullmq'); -const RedisServer = require('redis-server'); // Select ports that are unlikely to be used by other services a developer might be running locally. const HTTP_SERVER_PORT = 4735; -const REDIS_SERVER_PORT = 4736; - -// Create a Redis server. This is only for convenience +const REDIS_SERVER_PORT = 6379; async function main() { - const server = new RedisServer(REDIS_SERVER_PORT); - await server.open(); const queueName = 'name_of_my_queue'; const parentQueueName = 'name_of_my_parent_queue'; diff --git a/example/docker-compose.yml b/example/docker-compose.yml new file mode 100644 index 00000000..e6d9398a --- /dev/null +++ b/example/docker-compose.yml @@ -0,0 +1,7 @@ +version: '3.2' +services: + redis: + image: redis:7-alpine + container_name: cache + ports: + - 6379:6379 diff --git a/example/express.js b/example/express.js index 03a8e700..abbc071f 100644 --- a/example/express.js +++ b/example/express.js @@ -1,18 +1,13 @@ const Arena = require('../'); const express = require('express'); const {Queue, Worker, FlowProducer} = require('bullmq'); -const RedisServer = require('redis-server'); // Select ports that are unlikely to be used by other services a developer might be running locally. const HTTP_SERVER_PORT = 4735; -const REDIS_SERVER_PORT = 4736; - -// Create a Redis server. This is only for convenience +const REDIS_SERVER_PORT = 6379; async function main() { const app = express(); - const server = new RedisServer(REDIS_SERVER_PORT); - await server.open(); const queueName = 'name_of_my_queue'; const parentQueueName = 'name_of_my_parent_queue'; diff --git a/example/fastify.js b/example/fastify.js index b2e13757..2b3384a3 100644 --- a/example/fastify.js +++ b/example/fastify.js @@ -1,18 +1,13 @@ const Arena = require('../'); const fastify = require('fastify'); const {Queue, Worker, FlowProducer} = require('bullmq'); -const RedisServer = require('redis-server'); // Select ports that are unlikely to be used by other services a developer might be running locally. const HTTP_SERVER_PORT = 4735; const REDIS_SERVER_PORT = 4736; -// Create a Redis server. This is only for convenience - async function main() { const app = fastify(); - const server = new RedisServer(REDIS_SERVER_PORT); - await server.open(); const queueName = 'name_of_my_queue'; const parentQueueName = 'name_of_my_parent_queue'; @@ -76,7 +71,7 @@ async function main() { // adding delayed jobs const delayedJob = await queue.add('delayed', {}, {delay: 60 * 1000}); - delayedJob.log('Log message'); + await delayedJob.log('Log message'); const arena = Arena( { diff --git a/example/package.json b/example/package.json index f0caa724..e1e794b1 100644 --- a/example/package.json +++ b/example/package.json @@ -4,6 +4,8 @@ "description": "An example project that uses Arena", "main": "bee.js", "scripts": { + "dc:up": "docker-compose -f docker-compose.yml up -d", + "dc:down": "docker-compose -f docker-compose.yml down", "start:fastify": "node fastify.js", "start:express": "node express.js", "start:bee": "node bee.js", @@ -20,7 +22,6 @@ "bull": "^3.22.6", "bullmq": "^3.0.0", "express": "^4.17.1", - "fastify": "^4.13.0", - "redis-server": "^1.2.2" + "fastify": "^4.13.0" } }