Skip to content

Commit

Permalink
chore: use redis container for testing (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Sep 1, 2023
1 parent d87df77 commit 5853b31
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 42 deletions.
19 changes: 17 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
## 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

`npm install`

## Running

`npm run start:fastify`

or

`npm run start:express`

or

`npm run start:bee`

or
Expand Down
8 changes: 1 addition & 7 deletions example/bee.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down
8 changes: 1 addition & 7 deletions example/bull.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions example/bullmq.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
7 changes: 1 addition & 6 deletions example/bullmq_with_flows.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
7 changes: 7 additions & 0 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.2'
services:
redis:
image: redis:7-alpine
container_name: cache
ports:
- 6379:6379
7 changes: 1 addition & 6 deletions example/express.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
7 changes: 1 addition & 6 deletions example/fastify.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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(
{
Expand Down
5 changes: 3 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}

0 comments on commit 5853b31

Please sign in to comment.