taskpace 0.0.0-stage → 1.1.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.
Potentially problematic release.
This version of taskpace might be problematic. Click here for more details.
- package/.babelrc.es5 +5 -0
- package/.babelrc.lib +9 -0
- package/.env +2 -0
- package/.travis.yml +25 -0
- package/LICENSE +20 -0
- package/README.md +474 -2
- package/bower.json +30 -0
- package/es5.js +5064 -0
- package/lib/Batcher.js +1 -0
- package/lib/DLList.js +1 -0
- package/lib/Events.js +1 -0
- package/lib/Group.js +1 -0
- package/lib/IORedisConnection.js +1 -0
- package/lib/Job.js +1 -0
- package/lib/LocalDatastore.js +1 -0
- package/lib/Queues.js +1 -0
- package/lib/RedisConnection.js +1 -0
- package/lib/RedisDatastore.js +1 -0
- package/lib/Scripts.js +1 -0
- package/lib/States.js +1 -0
- package/lib/Sync.js +1 -0
- package/lib/Taskpace.js +1 -0
- package/lib/TaskpaceError.js +1 -0
- package/lib/common.js +1 -0
- package/lib/es5.js +1 -0
- package/lib/index.js +1 -0
- package/lib/limit.js +1 -0
- package/lib/lua.json +24 -0
- package/lib/parser.js +1 -0
- package/lib/redis.js +1 -0
- package/lib/validate.js +1 -0
- package/lib/version.json +1 -0
- package/light.js +1524 -0
- package/package.json +53 -4
- package/rollup.config.es5.js +34 -0
- package/rollup.config.light.js +44 -0
- package/scripts/assemble_lua.js +25 -0
- package/scripts/build.sh +81 -0
- package/scripts/test_all.sh +20 -0
- package/scripts/version.js +3 -0
- package/src/Batcher.coffee +39 -0
- package/src/DLList.coffee +38 -0
- package/src/Events.coffee +38 -0
- package/src/Group.coffee +80 -0
- package/src/IORedisConnection.coffee +84 -0
- package/src/Job.coffee +98 -0
- package/src/LocalDatastore.coffee +140 -0
- package/src/Queues.coffee +28 -0
- package/src/RedisConnection.coffee +91 -0
- package/src/RedisDatastore.coffee +158 -0
- package/src/Scripts.coffee +151 -0
- package/src/States.coffee +43 -0
- package/src/Sync.coffee +28 -0
- package/src/Taskpace.coffee +298 -0
- package/src/TaskpaceError.coffee +3 -0
- package/src/es5.coffee +3 -0
- package/src/index.coffee +1 -0
- package/src/parser.coffee +10 -0
- package/src/redis/blacklist_client.lua +8 -0
- package/src/redis/check.lua +6 -0
- package/src/redis/conditions_check.lua +3 -0
- package/src/redis/current_reservoir.lua +1 -0
- package/src/redis/done.lua +3 -0
- package/src/redis/free.lua +5 -0
- package/src/redis/get_time.lua +7 -0
- package/src/redis/group_check.lua +1 -0
- package/src/redis/heartbeat.lua +1 -0
- package/src/redis/increment_reservoir.lua +10 -0
- package/src/redis/init.lua +105 -0
- package/src/redis/process_tick.lua +214 -0
- package/src/redis/queued.lua +10 -0
- package/src/redis/refresh_expiration.lua +11 -0
- package/src/redis/refs.lua +13 -0
- package/src/redis/register.lua +51 -0
- package/src/redis/register_client.lua +12 -0
- package/src/redis/running.lua +1 -0
- package/src/redis/submit.lua +74 -0
- package/src/redis/update_settings.lua +14 -0
- package/src/redis/validate_client.lua +5 -0
- package/src/redis/validate_keys.lua +3 -0
- package/taskpace.d.ts +629 -0
- package/taskpace.d.ts.ejs +588 -0
- package/test/DLList.js +148 -0
- package/test/batcher.js +209 -0
- package/test/cluster.js +1549 -0
- package/test/context.js +142 -0
- package/test/general.js +867 -0
- package/test/group.js +255 -0
- package/test/ioredis.js +135 -0
- package/test/node_redis.js +100 -0
- package/test/priority.js +184 -0
- package/test/promises.js +202 -0
- package/test/retries.js +237 -0
- package/test/spawn/increaseKeepAlive.js +17 -0
- package/test/spawn/refreshKeepAlive.js +17 -0
- package/test/states.js +103 -0
- package/test/stop.js +208 -0
- package/test/taskpace.js +7 -0
- package/test.ts +335 -0
package/test/stop.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var makeTest = require('./context')
|
|
2
|
+
var Taskpace = require('./taskpace')
|
|
3
|
+
var assert = require('assert')
|
|
4
|
+
|
|
5
|
+
describe('Stop', function () {
|
|
6
|
+
var c
|
|
7
|
+
|
|
8
|
+
afterEach(function () {
|
|
9
|
+
return c.limiter.disconnect(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('Should stop and drop the queue', function (done) {
|
|
13
|
+
c = makeTest({
|
|
14
|
+
maxConcurrent: 2,
|
|
15
|
+
minTime: 100,
|
|
16
|
+
trackDoneStatus: true
|
|
17
|
+
})
|
|
18
|
+
var submitFailed = false
|
|
19
|
+
var queuedDropped = false
|
|
20
|
+
var scheduledDropped = false
|
|
21
|
+
var dropped = 0
|
|
22
|
+
|
|
23
|
+
c.limiter.on('dropped', function () {
|
|
24
|
+
dropped++
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
c.pNoErrVal(c.limiter.schedule({id: '0'}, c.promise, null, 0), 0)
|
|
28
|
+
|
|
29
|
+
c.pNoErrVal(c.limiter.schedule({id: '1'}, c.slowPromise, 100, null, 1), 1)
|
|
30
|
+
|
|
31
|
+
c.limiter.schedule({id: '2'}, c.promise, null, 2)
|
|
32
|
+
.catch(function (err) {
|
|
33
|
+
c.mustEqual(err.message, 'Dropped!')
|
|
34
|
+
scheduledDropped = true
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
c.limiter.schedule({id: '3'}, c.promise, null, 3)
|
|
38
|
+
.catch(function (err) {
|
|
39
|
+
c.mustEqual(err.message, 'Dropped!')
|
|
40
|
+
queuedDropped = true
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
setTimeout(function () {
|
|
44
|
+
var counts = c.limiter.counts()
|
|
45
|
+
c.mustEqual(counts.RECEIVED, 0)
|
|
46
|
+
c.mustEqual(counts.QUEUED, 1)
|
|
47
|
+
c.mustEqual(counts.RUNNING, 1)
|
|
48
|
+
c.mustEqual(counts.EXECUTING, 1)
|
|
49
|
+
c.mustEqual(counts.DONE, 1)
|
|
50
|
+
|
|
51
|
+
c.limiter.stop({
|
|
52
|
+
enqueueErrorMessage: 'Stopped!',
|
|
53
|
+
dropErrorMessage: 'Dropped!'
|
|
54
|
+
})
|
|
55
|
+
.then(function () {
|
|
56
|
+
counts = c.limiter.counts()
|
|
57
|
+
c.mustEqual(submitFailed, true)
|
|
58
|
+
c.mustEqual(scheduledDropped, true)
|
|
59
|
+
c.mustEqual(queuedDropped, true)
|
|
60
|
+
c.mustEqual(dropped, 2)
|
|
61
|
+
c.mustEqual(counts.RECEIVED, 0)
|
|
62
|
+
c.mustEqual(counts.QUEUED, 0)
|
|
63
|
+
c.mustEqual(counts.RUNNING, 0)
|
|
64
|
+
c.mustEqual(counts.EXECUTING, 0)
|
|
65
|
+
c.mustEqual(counts.DONE, 2)
|
|
66
|
+
|
|
67
|
+
c.checkResultsOrder([[0], [1]])
|
|
68
|
+
done()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
c.limiter.schedule(() => Promise.resolve(true))
|
|
72
|
+
.catch(function (err) {
|
|
73
|
+
c.mustEqual(err.message, 'Stopped!')
|
|
74
|
+
submitFailed = true
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
}, 125)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('Should stop and let the queue finish', function (done) {
|
|
81
|
+
c = makeTest({
|
|
82
|
+
maxConcurrent: 1,
|
|
83
|
+
minTime: 100,
|
|
84
|
+
trackDoneStatus: true
|
|
85
|
+
})
|
|
86
|
+
var submitFailed = false
|
|
87
|
+
var dropped = 0
|
|
88
|
+
|
|
89
|
+
c.limiter.on('dropped', function () {
|
|
90
|
+
dropped++
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
c.pNoErrVal(c.limiter.schedule({id: '1'}, c.promise, null, 1), 1)
|
|
94
|
+
c.pNoErrVal(c.limiter.schedule({id: '2'}, c.promise, null, 2), 2)
|
|
95
|
+
c.pNoErrVal(c.limiter.schedule({id: '3'}, c.slowPromise, 100, null, 3), 3)
|
|
96
|
+
|
|
97
|
+
setTimeout(function () {
|
|
98
|
+
var counts = c.limiter.counts()
|
|
99
|
+
c.mustEqual(counts.RECEIVED, 0)
|
|
100
|
+
c.mustEqual(counts.QUEUED, 1)
|
|
101
|
+
c.mustEqual(counts.RUNNING, 1)
|
|
102
|
+
c.mustEqual(counts.EXECUTING, 0)
|
|
103
|
+
c.mustEqual(counts.DONE, 1)
|
|
104
|
+
|
|
105
|
+
c.limiter.stop({
|
|
106
|
+
enqueueErrorMessage: 'Stopped!',
|
|
107
|
+
dropWaitingJobs: false
|
|
108
|
+
})
|
|
109
|
+
.then(function () {
|
|
110
|
+
counts = c.limiter.counts()
|
|
111
|
+
c.mustEqual(submitFailed, true)
|
|
112
|
+
c.mustEqual(dropped, 0)
|
|
113
|
+
c.mustEqual(counts.RECEIVED, 0)
|
|
114
|
+
c.mustEqual(counts.QUEUED, 0)
|
|
115
|
+
c.mustEqual(counts.RUNNING, 0)
|
|
116
|
+
c.mustEqual(counts.EXECUTING, 0)
|
|
117
|
+
c.mustEqual(counts.DONE, 4)
|
|
118
|
+
|
|
119
|
+
c.checkResultsOrder([[1], [2], [3]])
|
|
120
|
+
done()
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
c.limiter.schedule(() => Promise.resolve(true))
|
|
124
|
+
.catch(function (err) {
|
|
125
|
+
c.mustEqual(err.message, 'Stopped!')
|
|
126
|
+
submitFailed = true
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
}, 75)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('Should still resolve when rejectOnDrop is false', function (done) {
|
|
133
|
+
c = makeTest({
|
|
134
|
+
maxConcurrent: 1,
|
|
135
|
+
minTime: 100,
|
|
136
|
+
rejectOnDrop: false
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
c.pNoErrVal(c.limiter.schedule({id: '1'}, c.promise, null, 1), 1)
|
|
140
|
+
c.pNoErrVal(c.limiter.schedule({id: '2'}, c.promise, null, 2), 2)
|
|
141
|
+
c.pNoErrVal(c.limiter.schedule({id: '3'}, c.slowPromise, 100, null, 3), 3)
|
|
142
|
+
|
|
143
|
+
c.limiter.stop()
|
|
144
|
+
.then(function () {
|
|
145
|
+
return c.limiter.stop()
|
|
146
|
+
})
|
|
147
|
+
.then(function () {
|
|
148
|
+
done(new Error("Should not be here"))
|
|
149
|
+
})
|
|
150
|
+
.catch(function (err) {
|
|
151
|
+
c.mustEqual(err.message, "stop() has already been called")
|
|
152
|
+
done()
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('Should not allow calling stop() twice when dropWaitingJobs=true', function (done) {
|
|
157
|
+
c = makeTest({
|
|
158
|
+
maxConcurrent: 1,
|
|
159
|
+
minTime: 100
|
|
160
|
+
})
|
|
161
|
+
var failed = 0
|
|
162
|
+
var handler = function (err) {
|
|
163
|
+
c.mustEqual(err.message, "This limiter has been stopped.")
|
|
164
|
+
failed++
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
c.pNoErrVal(c.limiter.schedule({id: '1'}, c.promise, null, 1), 1).catch(handler)
|
|
168
|
+
c.pNoErrVal(c.limiter.schedule({id: '2'}, c.promise, null, 2), 2).catch(handler)
|
|
169
|
+
c.pNoErrVal(c.limiter.schedule({id: '3'}, c.slowPromise, 100, null, 3), 3).catch(handler)
|
|
170
|
+
|
|
171
|
+
c.limiter.stop({ dropWaitingJobs: true })
|
|
172
|
+
.then(function () {
|
|
173
|
+
return c.limiter.stop({ dropWaitingJobs: true })
|
|
174
|
+
})
|
|
175
|
+
.then(function () {
|
|
176
|
+
done(new Error("Should not be here"))
|
|
177
|
+
})
|
|
178
|
+
.catch(function (err) {
|
|
179
|
+
c.mustEqual(err.message, "stop() has already been called")
|
|
180
|
+
c.mustEqual(failed, 3)
|
|
181
|
+
done()
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('Should not allow calling stop() twice when dropWaitingJobs=false', function (done) {
|
|
186
|
+
c = makeTest({
|
|
187
|
+
maxConcurrent: 1,
|
|
188
|
+
minTime: 100
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
c.pNoErrVal(c.limiter.schedule({id: '1'}, c.promise, null, 1), 1)
|
|
192
|
+
c.pNoErrVal(c.limiter.schedule({id: '2'}, c.promise, null, 2), 2)
|
|
193
|
+
c.pNoErrVal(c.limiter.schedule({id: '3'}, c.slowPromise, 100, null, 3), 3)
|
|
194
|
+
|
|
195
|
+
c.limiter.stop({ dropWaitingJobs: false })
|
|
196
|
+
.then(function () {
|
|
197
|
+
return c.limiter.stop({ dropWaitingJobs: false })
|
|
198
|
+
})
|
|
199
|
+
.then(function () {
|
|
200
|
+
done(new Error("Should not be here"))
|
|
201
|
+
})
|
|
202
|
+
.catch(function (err) {
|
|
203
|
+
c.mustEqual(err.message, "stop() has already been called")
|
|
204
|
+
done()
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
})
|
package/test/taskpace.js
ADDED
package/test.ts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
/// <reference path="taskpace.d.ts" />
|
|
2
|
+
|
|
3
|
+
import Taskpace from "taskpace";
|
|
4
|
+
// import * as assert from "assert";
|
|
5
|
+
function assert(b: boolean): void { }
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
This file is run by scripts/build.sh.
|
|
9
|
+
It is used to validate the typings in taskpace.d.ts.
|
|
10
|
+
The command is: tsc --noEmit --strictNullChecks test.ts
|
|
11
|
+
This file cannot be run directly.
|
|
12
|
+
In order to do that, you must comment out the first line,
|
|
13
|
+
and change "taskpace" to "." on the third line.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function withCb(foo: number, bar: () => void, cb: (err: any, result: string) => void) {
|
|
17
|
+
let s: string = `cb ${foo}`;
|
|
18
|
+
cb(null, s);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log(Taskpace);
|
|
22
|
+
|
|
23
|
+
let limiter = new Taskpace({
|
|
24
|
+
maxConcurrent: 5,
|
|
25
|
+
minTime: 1000,
|
|
26
|
+
highWater: 20,
|
|
27
|
+
strategy: Taskpace.strategy.LEAK,
|
|
28
|
+
reservoirRefreshInterval: 1000 * 60,
|
|
29
|
+
reservoirRefreshAmount: 10,
|
|
30
|
+
reservoirIncreaseInterval: 1000 * 60,
|
|
31
|
+
reservoirIncreaseAmount: 2,
|
|
32
|
+
reservoirIncreaseMaximum: 15
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
limiter.ready().then(() => { console.log('Ready') });
|
|
36
|
+
limiter.clients().client;
|
|
37
|
+
limiter.disconnect();
|
|
38
|
+
|
|
39
|
+
limiter.currentReservoir().then(function (x) {
|
|
40
|
+
if (x != null) {
|
|
41
|
+
let i: number = x;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
limiter.incrementReservoir(5).then(function (x) {
|
|
46
|
+
if (x != null) {
|
|
47
|
+
let i: number = x;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
limiter.running().then(function (x) {
|
|
52
|
+
let i: number = x;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
limiter.clusterQueued().then(function (x) {
|
|
56
|
+
let i: number = x;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
limiter.done().then(function (x) {
|
|
60
|
+
let i: number = x;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
limiter.submit(withCb, 1, () => {}, (err, result) => {
|
|
64
|
+
let s: string = result;
|
|
65
|
+
console.log(s);
|
|
66
|
+
assert(s == "cb 1");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function withPromise(foo: number, bar: () => void): PromiseLike<string> {
|
|
70
|
+
let s: string = `promise ${foo}`;
|
|
71
|
+
return Promise.resolve(s);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let foo: Promise<string> = limiter.schedule(withPromise, 1, () => {});
|
|
75
|
+
foo.then(function (result: string) {
|
|
76
|
+
let s: string = result;
|
|
77
|
+
console.log(s);
|
|
78
|
+
assert(s == "promise 1");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
limiter.on("message", (msg) => console.log(msg));
|
|
82
|
+
|
|
83
|
+
limiter.publish(JSON.stringify({ a: "abc", b: { c: 123 }}));
|
|
84
|
+
|
|
85
|
+
function checkEventInfo(info: Taskpace.EventInfo) {
|
|
86
|
+
const numArgs: number = info.args.length;
|
|
87
|
+
const id: string = info.options.id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
limiter.on('dropped', (info) => {
|
|
91
|
+
checkEventInfo(info)
|
|
92
|
+
const task: Function = info.task;
|
|
93
|
+
const promise: Promise<any> = info.promise;
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
limiter.on('received', (info) => {
|
|
97
|
+
checkEventInfo(info)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
limiter.on('queued', (info) => {
|
|
101
|
+
checkEventInfo(info)
|
|
102
|
+
const blocked: boolean = info.blocked;
|
|
103
|
+
const reachedHWM: boolean = info.reachedHWM;
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
limiter.on('scheduled', (info) => {
|
|
107
|
+
checkEventInfo(info)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
limiter.on('executing', (info) => {
|
|
111
|
+
checkEventInfo(info)
|
|
112
|
+
const count: number = info.retryCount;
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
limiter.on('failed', (error, info) => {
|
|
116
|
+
checkEventInfo(info)
|
|
117
|
+
const message: string = error.message;
|
|
118
|
+
const count: number = info.retryCount;
|
|
119
|
+
return Promise.resolve(10)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
limiter.on('failed', (error, info) => {
|
|
123
|
+
checkEventInfo(info)
|
|
124
|
+
const message: string = error.message;
|
|
125
|
+
const count: number = info.retryCount;
|
|
126
|
+
return Promise.resolve(null)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
limiter.on('failed', (error, info) => {
|
|
130
|
+
checkEventInfo(info)
|
|
131
|
+
const message: string = error.message;
|
|
132
|
+
const count: number = info.retryCount;
|
|
133
|
+
return Promise.resolve()
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
limiter.on('failed', (error, info) => {
|
|
137
|
+
checkEventInfo(info)
|
|
138
|
+
const message: string = error.message;
|
|
139
|
+
const count: number = info.retryCount;
|
|
140
|
+
return 10
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
limiter.on('failed', (error, info) => {
|
|
144
|
+
checkEventInfo(info)
|
|
145
|
+
const message: string = error.message;
|
|
146
|
+
const count: number = info.retryCount;
|
|
147
|
+
return null
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
limiter.on('failed', (error, info) => {
|
|
151
|
+
checkEventInfo(info)
|
|
152
|
+
const message: string = error.message;
|
|
153
|
+
const count: number = info.retryCount;
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
limiter.on('retry', (message: string, info) => {
|
|
157
|
+
checkEventInfo(info)
|
|
158
|
+
const count: number = info.retryCount;
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
limiter.on('done', (info) => {
|
|
162
|
+
checkEventInfo(info)
|
|
163
|
+
const count: number = info.retryCount;
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
let group = new Taskpace.Group({
|
|
167
|
+
maxConcurrent: 5,
|
|
168
|
+
minTime: 1000,
|
|
169
|
+
highWater: 10,
|
|
170
|
+
strategy: Taskpace.strategy.LEAK,
|
|
171
|
+
datastore: "ioredis",
|
|
172
|
+
clearDatastore: true,
|
|
173
|
+
clientOptions: {},
|
|
174
|
+
clusterNodes: []
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
group.on('created', (limiter, key) => {
|
|
178
|
+
assert(limiter.empty())
|
|
179
|
+
assert(key.length > 0)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
group.key("foo").submit(withCb, 2, () => {}, (err, result) => {
|
|
183
|
+
let s: string = `${result} foo`;
|
|
184
|
+
console.log(s);
|
|
185
|
+
assert(s == "cb 2 foo");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
group.key("bar").submit({ priority: 4 }, withCb, 3, () => {}, (err, result) => {
|
|
189
|
+
let s: string = `${result} bar`;
|
|
190
|
+
console.log(s);
|
|
191
|
+
assert(s == "cb 3 foo");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
let f1: Promise<string> = group.key("pizza").schedule(withPromise, 2, () => {});
|
|
195
|
+
f1.then(function (result: string) {
|
|
196
|
+
let s: string = result;
|
|
197
|
+
console.log(s);
|
|
198
|
+
assert(s == "promise 2");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
let f2: Promise<string> = group.key("pie").schedule({ priority: 4 }, withPromise, 3, () => {});
|
|
202
|
+
f2.then(function (result: string) {
|
|
203
|
+
let s: string = result;
|
|
204
|
+
console.log(s);
|
|
205
|
+
assert(s == "promise 3");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
let wrapped = limiter.wrap((a: number, b: number) => {
|
|
209
|
+
let s: string = `Total: ${a + b}`;
|
|
210
|
+
return Promise.resolve(s);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
wrapped(1, 2).then((x) => {
|
|
214
|
+
let s: string = x;
|
|
215
|
+
console.log(s);
|
|
216
|
+
assert(s == "Total: 3");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
wrapped.withOptions({ priority: 1, id: 'some-id' }, 9, 9).then((x) => {
|
|
220
|
+
let s: string = x;
|
|
221
|
+
console.log(s);
|
|
222
|
+
assert(s == "Total: 18");
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
let counts = limiter.counts();
|
|
226
|
+
console.log(`${counts.EXECUTING + 2}`);
|
|
227
|
+
console.log(limiter.jobStatus('some-id'))
|
|
228
|
+
console.log(limiter.jobs());
|
|
229
|
+
console.log(limiter.jobs(Taskpace.Status.RUNNING));
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
group.deleteKey("pizza")
|
|
233
|
+
.then(function (deleted: boolean) {
|
|
234
|
+
console.log(deleted)
|
|
235
|
+
});
|
|
236
|
+
group.updateSettings({ timeout: 5, maxConcurrent: null, reservoir: null });
|
|
237
|
+
|
|
238
|
+
let keys: string[] = group.keys();
|
|
239
|
+
assert(keys.length == 3);
|
|
240
|
+
|
|
241
|
+
group.clusterKeys()
|
|
242
|
+
.then(function (allKeys: string[]) {
|
|
243
|
+
let count = allKeys.length;
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
let queued: number = limiter.chain(group.key("pizza")).queued();
|
|
247
|
+
|
|
248
|
+
limiter.stop({
|
|
249
|
+
dropWaitingJobs: true,
|
|
250
|
+
dropErrorMessage: "Begone!",
|
|
251
|
+
enqueueErrorMessage: "Denied!"
|
|
252
|
+
}).then(() => {
|
|
253
|
+
console.log('All stopped.')
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
wrapped(4, 5).catch((e) => {
|
|
257
|
+
assert(e.message === "Denied!")
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
const id: string = limiter.id;
|
|
261
|
+
const datastore: string = limiter.datastore;
|
|
262
|
+
const channel: string = limiter.channel();
|
|
263
|
+
|
|
264
|
+
const redisConnection = new Taskpace.RedisConnection({
|
|
265
|
+
client: "NodeRedis client object",
|
|
266
|
+
clientOptions: {}
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
redisConnection.ready()
|
|
270
|
+
.then(function (redisConnectionClients) {
|
|
271
|
+
const client = redisConnectionClients.client;
|
|
272
|
+
const subscriber = redisConnectionClients.subscriber;
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
redisConnection.on("error", (err) => {
|
|
276
|
+
console.log(err.message)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
const limiterWithConn = new Taskpace({
|
|
280
|
+
connection: redisConnection
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
const ioredisConnection = new Taskpace.IORedisConnection({
|
|
284
|
+
client: "ioredis client object",
|
|
285
|
+
clientOptions: {},
|
|
286
|
+
clusterNodes: []
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
ioredisConnection.ready()
|
|
290
|
+
.then(function (ioredisConnectionClients) {
|
|
291
|
+
const client = ioredisConnectionClients.client;
|
|
292
|
+
const subscriber = ioredisConnectionClients.subscriber;
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
ioredisConnection.on("error", (err: Taskpace.TaskpaceError) => {
|
|
296
|
+
console.log(err.message)
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const groupWithConn = new Taskpace.Group({
|
|
300
|
+
connection: ioredisConnection
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
const limiterWithConnFromGroup = new Taskpace({
|
|
304
|
+
connection: groupWithConn.connection
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
const groupWithConnFromLimiter = new Taskpace.Group({
|
|
308
|
+
connection: limiterWithConn.connection
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
const batcher = new Taskpace.Batcher({
|
|
313
|
+
maxTime: 1000,
|
|
314
|
+
maxSize: 10
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
batcher.on("batch", (batch) => {
|
|
318
|
+
const len: number = batch.length
|
|
319
|
+
console.log("Number of elements:", len)
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
batcher.on("error", (err: Taskpace.TaskpaceError) => {
|
|
323
|
+
console.log(err.message)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
batcher.add("abc")
|
|
327
|
+
batcher.add({ xyz: 5 })
|
|
328
|
+
.then(() => console.log("Flushed!"))
|
|
329
|
+
|
|
330
|
+
const object = {}
|
|
331
|
+
const emitter = new Taskpace.Events(object)
|
|
332
|
+
const listenerCount: number = emitter.listenerCount('info')
|
|
333
|
+
emitter.trigger('info', 'hello', 'world', 123).then(function (result) {
|
|
334
|
+
console.log(result)
|
|
335
|
+
})
|