onjs 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ name: GitHub Actions
2
+ run-name: ${{ github.actor }} is testing and building changes
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ branches:
7
+ - master
8
+ pull_request:
9
+ release:
10
+ types: [published]
11
+
12
+ permissions:
13
+ contents: read
14
+ pull-requests: read
15
+
16
+ concurrency:
17
+ group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
18
+ cancel-in-progress: true
19
+
20
+ jobs:
21
+ test-and-build:
22
+ runs-on: ubuntu-latest
23
+ container: node:16-bullseye
24
+ services:
25
+ redis:
26
+ image: redis:alpine
27
+ ports:
28
+ - 19379:6379
29
+ options: >-
30
+ --health-cmd "redis-cli ping"
31
+ --health-interval 10s
32
+ --health-timeout 5s
33
+ --health-retries 5
34
+ rabbitmq:
35
+ image: rabbitmq:alpine
36
+ ports:
37
+ - 5672:5672
38
+ env:
39
+ RABBITMQ_ERLANG_COOKIE: SWQOKODSQALRPCLNMEQG
40
+ RABBITMQ_DEFAULT_USER: rabbitmq
41
+ RABBITMQ_DEFAULT_PASS: rabbitmq
42
+ RABBITMQ_DEFAULT_VHOST: /
43
+
44
+ steps:
45
+ - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
46
+ - name: Check out repository code
47
+ uses: actions/checkout@v3
48
+ - run: echo "The ${{ github.repository }} repository has been cloned to the runner."
49
+ - run: echo "The workflow is now ready to test your code on the runner."
50
+ - name: Installing dependencies
51
+ run: npm install
52
+
53
+ - name: Testing
54
+ run: npm test
55
+ - run: echo "Job's status is ${{ job.status }}."
56
+ - uses: actions/setup-node@v3
57
+ with:
58
+ node-version: '16.x'
59
+ registry-url: 'https://registry.npmjs.org'
60
+ - name: Publishing to NPM
61
+ run: npm publish
62
+ env:
63
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -142,7 +142,7 @@ var options = {
142
142
 
143
143
  var mqOptions = {
144
144
  exchange_name: 'onjs_test',
145
- url: 'amqp://rabbitmq:rabbitmq@localhost:35672/'
145
+ url: 'amqp://rabbitmq:rabbitmq@localhost:5672/'
146
146
  }
147
147
 
148
148
  var mq = new MQ(mqOptions)
@@ -1,16 +1,19 @@
1
1
  #!/bin/bash
2
2
 
3
3
  RABBIT_CONTAINER_NAME=onjs_rabbit_test
4
- RABBIT_CONTAINER_PORT1=34369
5
- RABBIT_CONTAINER_PORT2=35671
6
- RABBIT_CONTAINER_PORT3=35672
7
- RABBIT_CONTAINER_PORT4=46872
4
+ RABBIT_CONTAINER_PORT=5672
5
+
8
6
 
9
7
  REDIS_CONTAINER_NAME=onjs_redis_test
10
8
  REDIS_CONTAINER_PORT=19379
11
9
 
12
10
  function createRabbitContainer() {
13
- id=$(docker run -d --name ${RABBIT_CONTAINER_NAME} -p ${RABBIT_CONTAINER_PORT1}:4369 -p ${RABBIT_CONTAINER_PORT2}:5671 -p ${RABBIT_CONTAINER_PORT3}:5672 -p ${RABBIT_CONTAINER_PORT4}:25672 -e RABBITMQ_ERLANG_COOKIE=SWQOKODSQALRPCLNMEQG -e RABBITMQ_DEFAULT_USER=rabbitmq -e RABBITMQ_DEFAULT_PASS=rabbitmq -e RABBITMQ_DEFAULT_VHOST=/ --hostname rabbitmq rabbitmq:alpine)
11
+ id=$(docker run -d --name ${RABBIT_CONTAINER_NAME} \
12
+ -p ${RABBIT_CONTAINER_PORT}:5672 \
13
+ -e RABBITMQ_ERLANG_COOKIE=SWQOKODSQALRPCLNMEQG \
14
+ -e RABBITMQ_DEFAULT_USER=rabbitmq \
15
+ -e RABBITMQ_DEFAULT_PASS=rabbitmq \
16
+ -e RABBITMQ_DEFAULT_VHOST=/ rabbitmq:alpine)
14
17
  echo $id
15
18
  }
16
19
 
package/lib/on.js CHANGED
@@ -1,6 +1,5 @@
1
1
  var RedisQueue = require('bull');
2
2
  var _ = require('lodash')
3
- var Q = require('q')
4
3
  var EventEmitter = require('events')
5
4
  var utils = require('./utils')
6
5
  var hasProperties = utils.hasProperties
@@ -223,14 +222,12 @@ class On extends EventEmitter {
223
222
  this.queueInstance.on('queueEventReceived', async (data) => {
224
223
  try {
225
224
  let taskName = data.name
226
- this._eventLog('info', taskName, `Received task on queue ${taskName}`)
227
- this._eventLog('info', taskName, data.data)
225
+ this._eventLog('info', taskName, `Received task on queue ${taskName}`, data.data)
228
226
 
229
227
  let task = this._getEventByName(taskName)
230
228
 
231
229
  if (hasProperties(task) && !this._validationIsSuccess(task.eventName, data.data)) {
232
- this._log('error', `Validation failed for task ${task.eventName} due to missing properties, received data`)
233
- this._log('error', data.data)
230
+ this._log('error', `Validation failed for task ${task.eventName} due to missing properties, received data`, data.data)
234
231
  var error = new Error(`Validation failed for task ${task.eventName}`)
235
232
  error.event = task
236
233
 
@@ -263,12 +260,11 @@ class On extends EventEmitter {
263
260
  _onTaskReceived (task, data) {
264
261
  this._eventLog('info', task.eventName, 'Executing task callback for task')
265
262
 
266
- return Q.allSettled(task.actions.map((action) => {
263
+ return Promise.allSettled(task.actions.map((action) => {
267
264
  return action.call(task, data)
268
265
  }))
269
266
  .then((results) => {
270
- this._eventLog('info', task.eventName, 'Results of all executions for task ' + task.eventName)
271
- this._eventLog('info', task.eventName, results)
267
+ this._eventLog('info', task.eventName, 'Results of all executions for task ' + task.eventName, results)
272
268
  })
273
269
  .catch(err => {
274
270
  this._eventLog('error', task.eventName, err)
@@ -523,19 +519,17 @@ class On extends EventEmitter {
523
519
  this._eventLog('info', event.eventName, `Processing redis event ${event.eventName} and executing callback`)
524
520
  this._eventLog('info', event.eventName, `Calling event callback`)
525
521
 
526
- return Q.allSettled(event.actions.map((action) => {
522
+ return Promise.allSettled(event.actions.map((action) => {
527
523
  return action.call(event, data, next)
528
524
  }))
529
525
  .then((results) => {
530
- this._eventLog('info', event.eventName, 'Results of all executions')
531
- this._eventLog('info', event.eventName, results)
526
+ this._eventLog('info', event.eventName, 'Results of all executions', results)
532
527
  jobDone()
533
528
  })
534
529
  })
535
530
 
536
531
  event.redisQueue.on('error', err => {
537
- this._eventLog('error', event.eventName, 'Error on redis queue')
538
- this._eventLog('error', event.eventName, err)
532
+ this._eventLog('error', event.eventName, 'Error on redis queue', err)
539
533
  })
540
534
 
541
535
  event.redisQueue.add(processName, data, {
@@ -557,16 +551,16 @@ class On extends EventEmitter {
557
551
  }
558
552
  }
559
553
 
560
- _eventLog (type, eventName, message) {
554
+ _eventLog (type, eventName, message, metadata) {
561
555
  if (this.debugEnabled) {
562
- return this.logger[type](message)
556
+ return this.logger[type](message, metadata)
563
557
  }
564
558
 
565
559
  var eventIndex = this._getEventIndex(eventName)
566
560
  if (eventIndex >= 0) {
567
561
  var event = this.events[eventIndex]
568
562
  if (event.isLogged) {
569
- return this.logger[type](message)
563
+ return this.logger[type](message, metadata)
570
564
  }
571
565
  }
572
566
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onjs",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "On.js is an event library based on RabbitMQ that helps you control events on a microservices arquitecture",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,10 +28,8 @@
28
28
  "should": "^13.1.3"
29
29
  },
30
30
  "dependencies": {
31
- "amqplib": "^0.5.2",
32
- "bull": "^3.0.0-rc.4",
33
- "mocha": "^5.2.0",
34
- "q": "^1.5.0",
35
- "uuid": "^3.1.0"
31
+ "amqplib": "^0.10.3",
32
+ "bull": "^3.29.3",
33
+ "mocha": "^5.2.0"
36
34
  }
37
35
  }
@@ -14,11 +14,11 @@ describe('Queue', function () {
14
14
  var config = {
15
15
  mq: {
16
16
  exchange_name: 'onjs_test',
17
- url: 'amqp://rabbitmq:rabbitmq@localhost:35672/',
17
+ url: 'amqp://rabbitmq:rabbitmq@rabbitmq:5672/',
18
18
  },
19
19
  redis: {
20
20
  port: REDIS_PORT,
21
- host: '127.0.0.1'
21
+ host: 'redis'
22
22
  }
23
23
  }
24
24
 
@@ -13,11 +13,11 @@ describe('RPC', function () {
13
13
  var config = {
14
14
  mq: {
15
15
  exchange_name: 'onjs_test',
16
- url: 'amqp://rabbitmq:rabbitmq@localhost:35672/',
16
+ url: 'amqp://rabbitmq:rabbitmq@rabbitmq:5672/',
17
17
  },
18
18
  redis: {
19
19
  port: REDIS_PORT,
20
- host: '127.0.0.1'
20
+ host: 'redis'
21
21
  }
22
22
  }
23
23
 
@@ -17,11 +17,11 @@ describe('On.js', function () {
17
17
  var config = {
18
18
  mq: {
19
19
  exchange_name: 'onjs_test',
20
- url: 'amqp://rabbitmq:rabbitmq@localhost:35672/',
20
+ url: 'amqp://rabbitmq:rabbitmq@rabbitmq:5672/',
21
21
  },
22
22
  redis: {
23
23
  port: REDIS_PORT,
24
- host: '127.0.0.1'
24
+ host: 'redis'
25
25
  }
26
26
  }
27
27
 
@@ -12,11 +12,11 @@ describe('Topics', function () {
12
12
  var config = {
13
13
  mq: {
14
14
  exchange_name: 'onjs_test',
15
- url: 'amqp://rabbitmq:rabbitmq@localhost:35672/',
15
+ url: 'amqp://rabbitmq:rabbitmq@rabbitmq:5672/',
16
16
  },
17
17
  redis: {
18
18
  port: REDIS_PORT,
19
- host: '127.0.0.1'
19
+ host: 'redis'
20
20
  }
21
21
  }
22
22