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/DLList.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
var DLList = require('../lib/DLList')
|
|
2
|
+
var assert = require('assert')
|
|
3
|
+
var c = require('./context')({datastore: 'local'})
|
|
4
|
+
|
|
5
|
+
var fakeQueues = function () {
|
|
6
|
+
this._length = 0
|
|
7
|
+
this.incr = () => this._length++
|
|
8
|
+
this.decr = () => this._length--
|
|
9
|
+
this.fns = [this.incr, this.decr]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('DLList', function () {
|
|
13
|
+
|
|
14
|
+
it('Should be created and be empty', function () {
|
|
15
|
+
var queues = new fakeQueues()
|
|
16
|
+
var list = new DLList()
|
|
17
|
+
c.mustEqual(list.getArray().length, 0)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('Should be possible to append once', function () {
|
|
21
|
+
var queues = new fakeQueues()
|
|
22
|
+
var list = new DLList(...queues.fns)
|
|
23
|
+
list.push(5)
|
|
24
|
+
var arr = list.getArray()
|
|
25
|
+
c.mustEqual(arr.length, 1)
|
|
26
|
+
c.mustEqual(list.length, 1)
|
|
27
|
+
c.mustEqual(queues._length, 1)
|
|
28
|
+
c.mustEqual(arr[0], 5)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('Should be possible to append multiple times', function () {
|
|
32
|
+
var queues = new fakeQueues()
|
|
33
|
+
var list = new DLList(...queues.fns)
|
|
34
|
+
list.push(5)
|
|
35
|
+
list.push(6)
|
|
36
|
+
var arr = list.getArray()
|
|
37
|
+
c.mustEqual(arr.length, 2)
|
|
38
|
+
c.mustEqual(list.length, 2)
|
|
39
|
+
c.mustEqual(queues._length, 2)
|
|
40
|
+
c.mustEqual(arr[0], 5)
|
|
41
|
+
c.mustEqual(arr[1], 6)
|
|
42
|
+
|
|
43
|
+
list.push(10)
|
|
44
|
+
|
|
45
|
+
arr = list.getArray()
|
|
46
|
+
c.mustEqual(arr.length, 3)
|
|
47
|
+
c.mustEqual(list.length, 3)
|
|
48
|
+
c.mustEqual(arr[0], 5)
|
|
49
|
+
c.mustEqual(arr[1], 6)
|
|
50
|
+
c.mustEqual(arr[2], 10)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('Should be possible to shift an empty list', function () {
|
|
54
|
+
var queues = new fakeQueues()
|
|
55
|
+
var list = new DLList(...queues.fns)
|
|
56
|
+
c.mustEqual(list.length, 0)
|
|
57
|
+
assert(list.shift() === undefined)
|
|
58
|
+
var arr = list.getArray()
|
|
59
|
+
c.mustEqual(arr.length, 0)
|
|
60
|
+
c.mustEqual(list.length, 0)
|
|
61
|
+
assert(list.shift() === undefined)
|
|
62
|
+
arr = list.getArray()
|
|
63
|
+
c.mustEqual(arr.length, 0)
|
|
64
|
+
c.mustEqual(list.length, 0)
|
|
65
|
+
c.mustEqual(queues._length, 0)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('Should be possible to append then shift once', function () {
|
|
69
|
+
var queues = new fakeQueues()
|
|
70
|
+
var list = new DLList(...queues.fns)
|
|
71
|
+
list.push(5)
|
|
72
|
+
c.mustEqual(list.length, 1)
|
|
73
|
+
c.mustEqual(list.shift(), 5)
|
|
74
|
+
var arr = list.getArray()
|
|
75
|
+
c.mustEqual(arr.length, 0)
|
|
76
|
+
c.mustEqual(list.length, 0)
|
|
77
|
+
c.mustEqual(queues._length, 0)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('Should be possible to append then shift multiple times', function () {
|
|
81
|
+
var queues = new fakeQueues()
|
|
82
|
+
var list = new DLList(...queues.fns)
|
|
83
|
+
list.push(5)
|
|
84
|
+
c.mustEqual(list.length, 1)
|
|
85
|
+
c.mustEqual(list.shift(), 5)
|
|
86
|
+
c.mustEqual(list.length, 0)
|
|
87
|
+
|
|
88
|
+
list.push(6)
|
|
89
|
+
c.mustEqual(list.length, 1)
|
|
90
|
+
c.mustEqual(list.shift(), 6)
|
|
91
|
+
c.mustEqual(list.length, 0)
|
|
92
|
+
c.mustEqual(queues._length, 0)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('Should pass a full test', function () {
|
|
96
|
+
var queues = new fakeQueues()
|
|
97
|
+
var list = new DLList(...queues.fns)
|
|
98
|
+
list.push(10)
|
|
99
|
+
c.mustEqual(list.length, 1)
|
|
100
|
+
list.push("11")
|
|
101
|
+
c.mustEqual(list.length, 2)
|
|
102
|
+
list.push(12)
|
|
103
|
+
c.mustEqual(list.length, 3)
|
|
104
|
+
c.mustEqual(queues._length, 3)
|
|
105
|
+
|
|
106
|
+
c.mustEqual(list.shift(), 10)
|
|
107
|
+
c.mustEqual(list.length, 2)
|
|
108
|
+
c.mustEqual(list.shift(),"11")
|
|
109
|
+
c.mustEqual(list.length, 1)
|
|
110
|
+
|
|
111
|
+
list.push(true)
|
|
112
|
+
c.mustEqual(list.length, 2)
|
|
113
|
+
|
|
114
|
+
var arr = list.getArray()
|
|
115
|
+
c.mustEqual(arr[0], 12)
|
|
116
|
+
c.mustEqual(arr[1], true)
|
|
117
|
+
c.mustEqual(arr.length, 2)
|
|
118
|
+
c.mustEqual(queues._length, 2)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('Should return the first value without shifting', function () {
|
|
122
|
+
var queues = new fakeQueues()
|
|
123
|
+
var list = new DLList(...queues.fns)
|
|
124
|
+
assert(list.first() === undefined)
|
|
125
|
+
assert(list.first() === undefined)
|
|
126
|
+
|
|
127
|
+
list.push(1)
|
|
128
|
+
c.mustEqual(list.first(), 1)
|
|
129
|
+
c.mustEqual(list.first(), 1)
|
|
130
|
+
|
|
131
|
+
list.push(2)
|
|
132
|
+
c.mustEqual(list.first(), 1)
|
|
133
|
+
c.mustEqual(list.first(), 1)
|
|
134
|
+
|
|
135
|
+
c.mustEqual(list.shift(), 1)
|
|
136
|
+
c.mustEqual(list.first(), 2)
|
|
137
|
+
c.mustEqual(list.first(), 2)
|
|
138
|
+
|
|
139
|
+
c.mustEqual(list.shift(), 2)
|
|
140
|
+
assert(list.first() === undefined)
|
|
141
|
+
assert(list.first() === undefined)
|
|
142
|
+
|
|
143
|
+
assert(list.first() === undefined)
|
|
144
|
+
assert(list.shift() === undefined)
|
|
145
|
+
assert(list.first() === undefined)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
})
|
package/test/batcher.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var makeTest = require('./context')
|
|
2
|
+
var Taskpace = require('./taskpace')
|
|
3
|
+
var assert = require('assert')
|
|
4
|
+
|
|
5
|
+
describe('Batcher', function () {
|
|
6
|
+
var c
|
|
7
|
+
|
|
8
|
+
afterEach(function () {
|
|
9
|
+
return c.limiter.disconnect(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('Should batch by time and size', function () {
|
|
13
|
+
c = makeTest()
|
|
14
|
+
var batcher = new Taskpace.Batcher({
|
|
15
|
+
maxTime: 50,
|
|
16
|
+
maxSize: 3
|
|
17
|
+
})
|
|
18
|
+
var t0 = Date.now()
|
|
19
|
+
var batches = []
|
|
20
|
+
|
|
21
|
+
batcher.on('batch', function (batcher) {
|
|
22
|
+
batches.push(batcher)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return Promise.all([
|
|
26
|
+
batcher.add(1).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 1)),
|
|
27
|
+
batcher.add(2).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 2)),
|
|
28
|
+
batcher.add(3).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 3)),
|
|
29
|
+
batcher.add(4).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 4)),
|
|
30
|
+
batcher.add(5).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 5))
|
|
31
|
+
])
|
|
32
|
+
.then(function (data) {
|
|
33
|
+
c.mustEqual(
|
|
34
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
35
|
+
[[0, 1], [0, 2], [0, 3], [1, 4], [1, 5]]
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return c.last()
|
|
39
|
+
})
|
|
40
|
+
.then(function (results) {
|
|
41
|
+
c.checkDuration(50, 20)
|
|
42
|
+
c.mustEqual(batches, [[1, 2, 3], [4, 5]])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('Should batch by time', function () {
|
|
47
|
+
c = makeTest()
|
|
48
|
+
var batcher = new Taskpace.Batcher({
|
|
49
|
+
maxTime: 50
|
|
50
|
+
})
|
|
51
|
+
var t0 = Date.now()
|
|
52
|
+
var batches = []
|
|
53
|
+
|
|
54
|
+
batcher.on('batch', function (batcher) {
|
|
55
|
+
batches.push(batcher)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return Promise.all([
|
|
59
|
+
batcher.add(1).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 1)),
|
|
60
|
+
batcher.add(2).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 2))
|
|
61
|
+
])
|
|
62
|
+
.then(function (data) {
|
|
63
|
+
c.mustEqual(
|
|
64
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
65
|
+
[[1, 1], [1, 2]]
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return Promise.all([
|
|
69
|
+
batcher.add(3).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 3)),
|
|
70
|
+
batcher.add(4).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 4))
|
|
71
|
+
])
|
|
72
|
+
})
|
|
73
|
+
.then(function (data) {
|
|
74
|
+
c.mustEqual(
|
|
75
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
76
|
+
[[2, 3], [2, 4]]
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
return c.last()
|
|
80
|
+
})
|
|
81
|
+
.then(function (results) {
|
|
82
|
+
c.checkDuration(100)
|
|
83
|
+
c.mustEqual(batches, [[1, 2], [3, 4]])
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('Should batch by size', function () {
|
|
88
|
+
c = makeTest()
|
|
89
|
+
var batcher = new Taskpace.Batcher({
|
|
90
|
+
maxSize: 2
|
|
91
|
+
})
|
|
92
|
+
var batches = []
|
|
93
|
+
|
|
94
|
+
batcher.on('batch', function (batcher) {
|
|
95
|
+
batches.push(batcher)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
return Promise.all([
|
|
99
|
+
batcher.add(1).then((x) => c.limiter.schedule(c.promise, null, 1)),
|
|
100
|
+
batcher.add(2).then((x) => c.limiter.schedule(c.promise, null, 2))
|
|
101
|
+
])
|
|
102
|
+
.then(function () {
|
|
103
|
+
return Promise.all([
|
|
104
|
+
batcher.add(3).then((x) => c.limiter.schedule(c.promise, null, 3)),
|
|
105
|
+
batcher.add(4).then((x) => c.limiter.schedule(c.promise, null, 4))
|
|
106
|
+
])
|
|
107
|
+
})
|
|
108
|
+
.then(c.last)
|
|
109
|
+
.then(function (results) {
|
|
110
|
+
c.checkDuration(0)
|
|
111
|
+
c.mustEqual(batches, [[1, 2], [3, 4]])
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('Should stagger flushes', function () {
|
|
116
|
+
c = makeTest()
|
|
117
|
+
var batcher = new Taskpace.Batcher({
|
|
118
|
+
maxTime: 50,
|
|
119
|
+
maxSize: 3
|
|
120
|
+
})
|
|
121
|
+
var t0 = Date.now()
|
|
122
|
+
var batches = []
|
|
123
|
+
|
|
124
|
+
batcher.on('batch', function (batcher) {
|
|
125
|
+
batches.push(batcher)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
return Promise.all([
|
|
129
|
+
batcher.add(1).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 1)),
|
|
130
|
+
batcher.add(2).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 2))
|
|
131
|
+
])
|
|
132
|
+
.then(function (data) {
|
|
133
|
+
c.mustEqual(
|
|
134
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
135
|
+
[[1, 1], [1, 2]]
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
var promises = []
|
|
139
|
+
promises.push(batcher.add(3).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 3)))
|
|
140
|
+
|
|
141
|
+
return c.wait(10)
|
|
142
|
+
.then(function () {
|
|
143
|
+
promises.push(batcher.add(4).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 4)))
|
|
144
|
+
|
|
145
|
+
return Promise.all(promises)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
.then(function (data) {
|
|
149
|
+
c.mustEqual(
|
|
150
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
151
|
+
[[2, 3], [2, 4]]
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
return c.last()
|
|
155
|
+
})
|
|
156
|
+
.then(function (results) {
|
|
157
|
+
c.checkDuration(120, 20)
|
|
158
|
+
c.mustEqual(batches, [[1, 2], [3, 4]])
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('Should force then stagger flushes', function () {
|
|
163
|
+
c = makeTest()
|
|
164
|
+
var batcher = new Taskpace.Batcher({
|
|
165
|
+
maxTime: 50,
|
|
166
|
+
maxSize: 3
|
|
167
|
+
})
|
|
168
|
+
var t0 = Date.now()
|
|
169
|
+
var batches = []
|
|
170
|
+
|
|
171
|
+
batcher.on('batch', function (batcher) {
|
|
172
|
+
batches.push(batcher)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
var promises = []
|
|
176
|
+
promises.push(batcher.add(1).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 1)))
|
|
177
|
+
promises.push(batcher.add(2).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 2)))
|
|
178
|
+
|
|
179
|
+
return c.wait(10)
|
|
180
|
+
.then(function () {
|
|
181
|
+
promises.push(batcher.add(3).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 3)))
|
|
182
|
+
|
|
183
|
+
return Promise.all(promises)
|
|
184
|
+
})
|
|
185
|
+
.then(function (data) {
|
|
186
|
+
c.mustEqual(
|
|
187
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
188
|
+
[[0, 1], [0, 2], [0, 3]]
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return Promise.all([
|
|
192
|
+
batcher.add(4).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 4)),
|
|
193
|
+
batcher.add(5).then((x) => c.limiter.schedule(c.promise, null, Date.now() - t0, 5)),
|
|
194
|
+
])
|
|
195
|
+
})
|
|
196
|
+
.then(function (data) {
|
|
197
|
+
c.mustEqual(
|
|
198
|
+
data.map((([t, x]) => [Math.floor(t / 50), x])),
|
|
199
|
+
[[1, 4], [1, 5]]
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
return c.last()
|
|
203
|
+
})
|
|
204
|
+
.then(function (results) {
|
|
205
|
+
c.checkDuration(85, 25)
|
|
206
|
+
c.mustEqual(batches, [[1, 2, 3], [4, 5]])
|
|
207
|
+
})
|
|
208
|
+
})
|
|
209
|
+
})
|