Skip to content

Commit

Permalink
Merge pull request #1 from diflores/feat/dockerize
Browse files Browse the repository at this point in the history
Feat/dockerize
  • Loading branch information
diflores authored Jul 29, 2022
2 parents f131b45 + 352be97 commit 36069e1
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:16.13
COPY package.json package-lock.json ./
RUN npm ci
WORKDIR /usr/src/app
COPY src ./
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ I made a simple POC for killing Bull jobs using [Alexander Lolis implementation]

## How to run

1. Run `npm install`
2. Start the queue in one terminal: `node queue.js`
3. Run the main process in another terminal: `node main.js`
### Without Docker

1. Run `npm install`.
2. Start the queue in one terminal: `node queue.js`.
3. Run the main process in another terminal: `node main.js`.

### With Docker
1. Run `docker-compose up`.
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.9"
services:
queue:
build: .
command: [ "node", "queue.js" ]
environment:
- REDIS_URL=redis://redis:6379
links:
- redis
main:
build: .
command: [ "node", "main.js" ]
environment:
- REDIS_URL=redis://redis:6379
links:
- redis
redis:
image: redis
ports:
- "6379:6379"
2 changes: 2 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379';
module.exports = REDIS_URL;
3 changes: 2 additions & 1 deletion main.js → src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const Queue = require('bull');
const REDIS_URL = require('./consts');

function main() {
const myQueue = new Queue('myQueue', 'redis://localhost:6379');
const myQueue = new Queue('myQueue', REDIS_URL);
myQueue.add({ commonName: 'job_1', timeToFinish: 100000 }, { attempts: 1 });
myQueue.add({ commonName: 'job_2', timeToFinish: 5000 }, { attempts: 1 });
myQueue.add({ commonName: 'job_3', timeToFinish: 6000 }, { attempts: 1 });
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion queue.js → src/queue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Queue = require('bull');
const kill = require('tree-kill');
const REDIS_URL = require('./consts');

const MAX_TTL = 5000;
const CONCURRENCY = 2;
Expand Down Expand Up @@ -45,7 +46,7 @@ function checkIfJobsToKill(myQueue) {
}

function createQueue() {
const myQueue = new Queue('myQueue', 'redis://localhost:6379');
const myQueue = new Queue('myQueue', REDIS_URL);
myQueue.process(CONCURRENCY, `${__dirname}/process.js`);
myQueue.on('active', () => checkIfJobsToKill(myQueue));
myQueue.on('failed', (job) => console.log('Job failed', job.id, job.stacktrace));
Expand Down
File renamed without changes.

0 comments on commit 36069e1

Please sign in to comment.