Skip to content

Commit bd27314

Browse files
committed
fixing check status behavior and documentation
1 parent 769571d commit bd27314

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ node sample/multi-producer.js default 60 '{"data":"mydata"}'
205205
206206
If you use parallel processing with multiple workers, finding out when all jobs have completed successfully can be a complicated task due to asynchrony.
207207
208-
To deal with this, Taurus has a functionality that uses a Redis + Lua solution to ensure that the last job in a group was executed, to use it you need to increment a list using a unique specific key when sending to each queue, and decrement this key to each queue that runs successfully.
208+
To deal with this, Taurus has a functionality that uses a Redis + Lua solution to ensure that the last job in a group was executed, to use it you will need to set a unique specific key with the amount of total queues you wanto to excecute, before sending to the queues, and decrement this key to each queue that runs successfully.
209209
210210
The last queue will know it is last and will allow you to perform finishing actions.
211211
@@ -218,13 +218,14 @@ AUX_REDIS_HOST=taurus-redis
218218
AUX_REDIS_PORT=6379
219219
```
220220
221-
2) When inserting into each queue you can use the CheckCompletion class to increment each job: (If you are outside the Taurus ecosystem you can just create a key in redis with [INCR command](https://redis.io/commands/incr/) with your favorite language.)
221+
2) When inserting into each queue you can use the CheckCompletion class to increment each job: (If you are outside the Taurus ecosystem you can just create a key in redis with [SET command](https://redis.io/commands/set/) on your favorite language but the value MUST BE INTEGER greater than 0.)
222222
223223
```js
224224
const CheckCompletion = require('../core/check-completion.js');
225225
...
226+
const numberOfJobs = Number (100);
226227
const checkCompletion = new CheckCompletion();
227-
await checkCompletion.increment(uniqueKeyToRepresenTheGroup);
228+
await checkCompletion.setInitialJobCounter(uniqueKeyToRepresenTheGroup, numberOfJobs);
228229
```
229230
230231
3) When each queue has finished executing, just call the decrement command and check if it returned zero, if it returned zero, this queue is the last one of this group and you can execute any command you find necessary

core/check-completion.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ class CheckCompletion {
99
};
1010
}
1111

12-
async increment(
12+
async setInitialJobCounter(
1313
key,
14+
value,
1415
) {
1516
const redis = new Redis(
1617
this.options,
1718
);
1819

19-
const result = await redis.incr(key);
20-
console.log(`Job counter key: ${key}, increased, total jobs: ${result}`);
20+
const result = await redis.set(key, value);
21+
console.log(`Job counter key: ${key}, increased, total jobs: ${value}`);
2122

2223
await redis.disconnect();
2324
return result;

core/push-queue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PushQueue {
4343
queueName,
4444
data,
4545
time,
46+
options = {},
4647
) {
4748
const queue = new Bull(
4849
queueName,
@@ -58,6 +59,7 @@ class PushQueue {
5859
attempts: configQueue.attempts,
5960
backoff: configQueue.backoff,
6061
jobId: ulid.ulid(),
62+
...options,
6163
},
6264
);
6365

0 commit comments

Comments
 (0)