onjs 2.2.1 → 2.3.1
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.
- package/.github/workflows/github-actions.yml +14 -7
- package/README.md +11 -1
- package/lib/on.js +28 -12
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ on:
|
|
|
12
12
|
permissions:
|
|
13
13
|
contents: read
|
|
14
14
|
pull-requests: read
|
|
15
|
+
id-token: write
|
|
15
16
|
|
|
16
17
|
concurrency:
|
|
17
18
|
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
|
|
@@ -44,20 +45,26 @@ jobs:
|
|
|
44
45
|
steps:
|
|
45
46
|
- run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
|
46
47
|
- name: Check out repository code
|
|
47
|
-
uses: actions/checkout@
|
|
48
|
+
uses: actions/checkout@v4
|
|
49
|
+
|
|
48
50
|
- run: echo "The ${{ github.repository }} repository has been cloned to the runner."
|
|
49
51
|
- run: echo "The workflow is now ready to test your code on the runner."
|
|
52
|
+
|
|
53
|
+
# Setup .npmrc file to publish to npm
|
|
54
|
+
- uses: actions/setup-node@v4
|
|
55
|
+
with:
|
|
56
|
+
node-version: '20.x'
|
|
57
|
+
registry-url: 'https://registry.npmjs.org'
|
|
58
|
+
|
|
50
59
|
- name: Installing dependencies
|
|
51
|
-
run: npm
|
|
60
|
+
run: npm ci
|
|
52
61
|
|
|
53
62
|
- name: Testing
|
|
54
63
|
run: npm test
|
|
64
|
+
|
|
55
65
|
- run: echo "Job's status is ${{ job.status }}."
|
|
56
|
-
|
|
57
|
-
with:
|
|
58
|
-
node-version: '16.x'
|
|
59
|
-
registry-url: 'https://registry.npmjs.org'
|
|
66
|
+
|
|
60
67
|
- name: Publishing to NPM
|
|
61
|
-
run: npm publish
|
|
68
|
+
run: npm publish --provenance --access public
|
|
62
69
|
env:
|
|
63
70
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ To achieve this on On.js you have to register the event, declare the properties
|
|
|
22
22
|
|
|
23
23
|
On.js uses it's own local Redis based queue to order to avoid duplicates if multiple services listen to the same event
|
|
24
24
|
|
|
25
|
-
On.js provides
|
|
25
|
+
On.js provides three options for working with topics. Processing, Dispatching and Broadcasting
|
|
26
26
|
|
|
27
27
|
Processing means that the task will be added to the queue and processed as soon as the queue determines that it can start processing it.
|
|
28
28
|
|
|
@@ -36,6 +36,16 @@ on
|
|
|
36
36
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
Broadcasting means that the task will immediately be executed by ALL the listeners without using redis, the tasks will be "duplicated" across all listeners.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
on
|
|
43
|
+
.broadcastReceived(eventName: string)
|
|
44
|
+
.do(callback: function)
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
39
49
|
#### Processing
|
|
40
50
|
|
|
41
51
|
```
|
package/lib/on.js
CHANGED
|
@@ -189,21 +189,18 @@ class On extends EventEmitter {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
async _onTopicReceived (event, data) {
|
|
192
|
-
|
|
193
|
-
this._eventLog('info', event.eventName, `Creating redis queue with name ${event.eventName}`)
|
|
192
|
+
this._eventLog('info', event.eventName, `Creating topic queue with name ${event.eventName}`)
|
|
194
193
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
this._eventLog('info', event.eventName, `Sending the event to redis as task ${event.eventName}`)
|
|
201
|
-
this._sendToRedisQueueToProcess(event, data)
|
|
202
|
-
}
|
|
194
|
+
if (event.dispatchAs && event.dispatchAs.length > 0) {
|
|
195
|
+
this._eventLog('info', event.eventName, `Event is redispatchable`)
|
|
196
|
+
return this._redispatchToMQ(event, data)
|
|
203
197
|
}
|
|
204
|
-
|
|
205
|
-
|
|
198
|
+
if (event.asTask) {
|
|
199
|
+
this._eventLog('info', event.eventName, `Event is going to execute as task`)
|
|
200
|
+
return this._onTaskReceived(event, data)
|
|
206
201
|
}
|
|
202
|
+
this._eventLog('info', event.eventName, `Sending the event to redis as task ${event.eventName}`)
|
|
203
|
+
this._sendToRedisQueueToProcess(event, data)
|
|
207
204
|
}
|
|
208
205
|
|
|
209
206
|
// Consume queue events from MQ
|
|
@@ -318,6 +315,25 @@ class On extends EventEmitter {
|
|
|
318
315
|
return this
|
|
319
316
|
}
|
|
320
317
|
|
|
318
|
+
broadcastReceived (eventName) {
|
|
319
|
+
this.currentEventNameToRegister = eventName
|
|
320
|
+
this.currentEventTypeToRegister = 'topic'
|
|
321
|
+
|
|
322
|
+
if (this._eventExists(eventName, 'topic')) {
|
|
323
|
+
this._eventLog('info', eventName, `The event ${eventName} is already registered`)
|
|
324
|
+
throw new Error(`The event ${eventName} is already registered, possibly as eventReceived`)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
this.events.push({
|
|
328
|
+
eventName: eventName,
|
|
329
|
+
type: 'topic',
|
|
330
|
+
asTask: true,
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
this._eventLog('info', eventName, `Registered event ${eventName} as broadcast`)
|
|
334
|
+
return this
|
|
335
|
+
}
|
|
336
|
+
|
|
321
337
|
taskReceived (taskName, options = { isDelayed: false }) {
|
|
322
338
|
const eventType = options.isDelayed ? 'delayedQueue' : 'queue'
|
|
323
339
|
this.currentEventNameToRegister = taskName
|