redis-smq-common 1.0.0 → 1.0.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/CHANGELOG.md +7 -0
- package/dist/src/async/async.js +8 -6
- package/dist/src/worker/worker-error.d.ts +3 -0
- package/dist/src/worker/worker-error.js +8 -0
- package/dist/src/worker/worker-runner/worker-pool.d.ts +0 -2
- package/dist/src/worker/worker-runner/worker-pool.js +3 -15
- package/dist/src/worker/worker.js +4 -4
- package/package.json +1 -1
- package/dist/src/worker/worker-runner/worker-runner.error.d.ts +0 -3
- package/dist/src/worker/worker-runner/worker-runner.error.js +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.0.1 (2022-07-07)
|
|
4
|
+
|
|
5
|
+
* Remove unused WorkerRunnerError (48e7206)
|
|
6
|
+
* Use namespaced WorkerError (517224c)
|
|
7
|
+
* Make array looping asynchronous (cd66e51)
|
|
8
|
+
* Run workers one by one without a delay (099b488)
|
|
9
|
+
|
|
3
10
|
## 1.0.0 (20220-06-18)
|
|
4
11
|
|
|
5
12
|
* Rename logger/test00018 (f20fdf9)
|
package/dist/src/async/async.js
CHANGED
|
@@ -10,7 +10,7 @@ const eachOf = (collection, iteratee, callback) => {
|
|
|
10
10
|
if (err || idx >= collection.length)
|
|
11
11
|
callback(err);
|
|
12
12
|
else
|
|
13
|
-
iterate();
|
|
13
|
+
setTimeout(() => iterate(), 0);
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
16
|
iterate();
|
|
@@ -30,7 +30,7 @@ const eachIn = (collection, iteratee, callback) => {
|
|
|
30
30
|
if (err || idx >= keys.length)
|
|
31
31
|
callback(err);
|
|
32
32
|
else
|
|
33
|
-
iterate();
|
|
33
|
+
setTimeout(() => iterate(), 0);
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
iterate();
|
|
@@ -53,10 +53,12 @@ const waterfall = (tasks, callback) => {
|
|
|
53
53
|
callback(err);
|
|
54
54
|
}
|
|
55
55
|
else if (idx < tasks.length) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
if (args.length)
|
|
58
|
+
tasks[idx](...args, exec);
|
|
59
|
+
else
|
|
60
|
+
tasks[idx](exec);
|
|
61
|
+
}, 0);
|
|
60
62
|
}
|
|
61
63
|
else if (args.length) {
|
|
62
64
|
callback(null, args[0]);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerError = void 0;
|
|
4
|
+
const panic_error_1 = require("../errors/panic.error");
|
|
5
|
+
class WorkerError extends panic_error_1.PanicError {
|
|
6
|
+
}
|
|
7
|
+
exports.WorkerError = WorkerError;
|
|
8
|
+
//# sourceMappingURL=worker-error.js.map
|
|
@@ -2,8 +2,6 @@ import { Worker } from '../worker';
|
|
|
2
2
|
import { ICallback } from '../../../types';
|
|
3
3
|
export declare class WorkerPool {
|
|
4
4
|
private pool;
|
|
5
|
-
private index;
|
|
6
|
-
private getCurrentPoolItem;
|
|
7
5
|
work: (cb: ICallback<void>) => void;
|
|
8
6
|
add: (worker: Worker) => number;
|
|
9
7
|
clear: (cb: ICallback<void>) => void;
|
|
@@ -5,22 +5,11 @@ const async_1 = require("../../async/async");
|
|
|
5
5
|
class WorkerPool {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.pool = [];
|
|
8
|
-
this.
|
|
9
|
-
this.getCurrentPoolItem = () => {
|
|
8
|
+
this.work = (cb) => {
|
|
10
9
|
if (this.pool.length) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
if (this.index >= this.pool.length) {
|
|
14
|
-
this.index = 0;
|
|
15
|
-
}
|
|
16
|
-
return worker;
|
|
10
|
+
const tasks = this.pool.map((worker) => (cb) => worker.work(cb));
|
|
11
|
+
async_1.async.waterfall(tasks, cb);
|
|
17
12
|
}
|
|
18
|
-
return null;
|
|
19
|
-
};
|
|
20
|
-
this.work = (cb) => {
|
|
21
|
-
const worker = this.getCurrentPoolItem();
|
|
22
|
-
if (worker)
|
|
23
|
-
worker.work(cb);
|
|
24
13
|
else
|
|
25
14
|
cb();
|
|
26
15
|
};
|
|
@@ -33,7 +22,6 @@ class WorkerPool {
|
|
|
33
22
|
worker.quit(done);
|
|
34
23
|
}, () => {
|
|
35
24
|
this.pool = [];
|
|
36
|
-
this.index = 0;
|
|
37
25
|
cb();
|
|
38
26
|
});
|
|
39
27
|
};
|
|
@@ -4,14 +4,14 @@ exports.Worker = void 0;
|
|
|
4
4
|
const ticker_1 = require("../ticker/ticker");
|
|
5
5
|
const events_1 = require("../events/events");
|
|
6
6
|
const power_manager_1 = require("../power-manager/power-manager");
|
|
7
|
-
const
|
|
7
|
+
const worker_error_1 = require("./worker-error");
|
|
8
8
|
class Worker {
|
|
9
9
|
constructor(managed, timeout = 1000) {
|
|
10
10
|
this.ticker = null;
|
|
11
11
|
this.powerManager = null;
|
|
12
12
|
this.getTicker = () => {
|
|
13
13
|
if (!this.ticker) {
|
|
14
|
-
throw new
|
|
14
|
+
throw new worker_error_1.WorkerError(`Expected an instance of Ticker`);
|
|
15
15
|
}
|
|
16
16
|
return this.ticker;
|
|
17
17
|
};
|
|
@@ -24,7 +24,7 @@ class Worker {
|
|
|
24
24
|
};
|
|
25
25
|
this.run = () => {
|
|
26
26
|
if (this.managed) {
|
|
27
|
-
throw new
|
|
27
|
+
throw new worker_error_1.WorkerError('You can not run a managed worker');
|
|
28
28
|
}
|
|
29
29
|
const powerManager = this.getPowerManager();
|
|
30
30
|
powerManager.goingUp();
|
|
@@ -54,7 +54,7 @@ class Worker {
|
|
|
54
54
|
}
|
|
55
55
|
getPowerManager() {
|
|
56
56
|
if (!this.powerManager) {
|
|
57
|
-
throw new
|
|
57
|
+
throw new worker_error_1.WorkerError('Expected an instance of PowerManager');
|
|
58
58
|
}
|
|
59
59
|
return this.powerManager;
|
|
60
60
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WorkerRunnerError = void 0;
|
|
4
|
-
const redis_smq_error_1 = require("../../errors/redis-smq.error");
|
|
5
|
-
class WorkerRunnerError extends redis_smq_error_1.RedisSMQError {
|
|
6
|
-
}
|
|
7
|
-
exports.WorkerRunnerError = WorkerRunnerError;
|
|
8
|
-
//# sourceMappingURL=worker-runner.error.js.map
|