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/context.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
global.TEST = true
|
|
2
|
+
var Taskpace = require('./taskpace')
|
|
3
|
+
var assert = require('assert')
|
|
4
|
+
|
|
5
|
+
module.exports = function (options={}) {
|
|
6
|
+
var mustEqual = function (a, b) {
|
|
7
|
+
var strA = JSON.stringify(a)
|
|
8
|
+
var strB = JSON.stringify(b)
|
|
9
|
+
if (strA !== strB) {
|
|
10
|
+
console.log(strA + ' !== ' + strB, (new Error('').stack))
|
|
11
|
+
assert(strA === strB)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var start
|
|
16
|
+
var calls = []
|
|
17
|
+
|
|
18
|
+
// set options.datastore
|
|
19
|
+
var setRedisClientOptions = function (options) {
|
|
20
|
+
options.clearDatastore = true
|
|
21
|
+
if (options.clientOptions == null) {
|
|
22
|
+
options.clientOptions = {
|
|
23
|
+
host: process.env.REDIS_HOST,
|
|
24
|
+
port: process.env.REDIS_PORT,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (options.datastore == null && process.env.DATASTORE === 'redis') {
|
|
30
|
+
options.datastore = 'redis'
|
|
31
|
+
setRedisClientOptions(options)
|
|
32
|
+
} else if (options.datastore == null && process.env.DATASTORE === 'ioredis') {
|
|
33
|
+
options.datastore = 'ioredis'
|
|
34
|
+
setRedisClientOptions(options)
|
|
35
|
+
} else {
|
|
36
|
+
options.datastore = 'local'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var limiter = new Taskpace(options)
|
|
40
|
+
// limiter.on("debug", function (str, args) { console.log(`${Date.now()-start} ${str} ${JSON.stringify(args)}`) })
|
|
41
|
+
if (!options.errorEventsExpected) {
|
|
42
|
+
limiter.on("error", function (err) {
|
|
43
|
+
console.log('(CONTEXT) ERROR EVENT', err)
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
limiter.ready().then(function (client) {
|
|
47
|
+
start = Date.now()
|
|
48
|
+
})
|
|
49
|
+
var getResults = function () {
|
|
50
|
+
return {
|
|
51
|
+
elapsed: Date.now() - start,
|
|
52
|
+
callsDuration: calls.length > 0 ? calls[calls.length - 1].time : null,
|
|
53
|
+
calls: calls
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var context = {
|
|
58
|
+
job: function (err, ...result) {
|
|
59
|
+
var cb = result.pop()
|
|
60
|
+
calls.push({err: err, result: result, time: Date.now()-start})
|
|
61
|
+
if (process.env.DEBUG) console.log(result, calls)
|
|
62
|
+
cb.apply({}, [err].concat(result))
|
|
63
|
+
},
|
|
64
|
+
slowJob: function (duration, err, ...result) {
|
|
65
|
+
setTimeout(function () {
|
|
66
|
+
var cb = result.pop()
|
|
67
|
+
calls.push({err: err, result: result, time: Date.now()-start})
|
|
68
|
+
if (process.env.DEBUG) console.log(result, calls)
|
|
69
|
+
cb.apply({}, [err].concat(result))
|
|
70
|
+
}, duration)
|
|
71
|
+
},
|
|
72
|
+
promise: function (err, ...result) {
|
|
73
|
+
return new Promise(function (resolve, reject) {
|
|
74
|
+
if (process.env.DEBUG) console.log('In c.promise. Result: ', result)
|
|
75
|
+
calls.push({err: err, result: result, time: Date.now()-start})
|
|
76
|
+
if (process.env.DEBUG) console.log(result, calls)
|
|
77
|
+
if (err === null) {
|
|
78
|
+
return resolve(result)
|
|
79
|
+
} else {
|
|
80
|
+
return reject(err)
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
slowPromise: function (duration, err, ...result) {
|
|
85
|
+
return new Promise(function (resolve, reject) {
|
|
86
|
+
setTimeout(function () {
|
|
87
|
+
if (process.env.DEBUG) console.log('In c.slowPromise. Result: ', result)
|
|
88
|
+
calls.push({err: err, result: result, time: Date.now()-start})
|
|
89
|
+
if (process.env.DEBUG) console.log(result, calls)
|
|
90
|
+
if (err === null) {
|
|
91
|
+
return resolve(result)
|
|
92
|
+
} else {
|
|
93
|
+
return reject(err)
|
|
94
|
+
}
|
|
95
|
+
}, duration)
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
pNoErrVal: function (promise, ...expected) {
|
|
99
|
+
if (process.env.DEBUG) console.log('In c.pNoErrVal. Expected:', expected)
|
|
100
|
+
return promise.then(function (actual) {
|
|
101
|
+
mustEqual(actual, expected)
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
noErrVal: function (...expected) {
|
|
105
|
+
return function (err, ...actual) {
|
|
106
|
+
mustEqual(err, null)
|
|
107
|
+
mustEqual(actual, expected)
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
last: function (options) {
|
|
111
|
+
var opt = options != null ? options : {}
|
|
112
|
+
return limiter.schedule(opt, function () { return Promise.resolve(getResults()) })
|
|
113
|
+
.catch(function (err) { console.error("Error in context.last:", err)})
|
|
114
|
+
},
|
|
115
|
+
wait: function (wait) {
|
|
116
|
+
return new Promise(function (resolve, reject) {
|
|
117
|
+
setTimeout(resolve, wait)
|
|
118
|
+
})
|
|
119
|
+
},
|
|
120
|
+
limiter: limiter,
|
|
121
|
+
mustEqual: mustEqual,
|
|
122
|
+
mustExist: function (a) { assert(a != null) },
|
|
123
|
+
results: getResults,
|
|
124
|
+
checkResultsOrder: function (order) {
|
|
125
|
+
mustEqual(order.length, calls.length)
|
|
126
|
+
for (var i = 0; i < Math.max(calls.length, order.length); i++) {
|
|
127
|
+
mustEqual(order[i], calls[i].result)
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
checkDuration: function (shouldBe, minBound = 10) {
|
|
131
|
+
var results = getResults()
|
|
132
|
+
var min = shouldBe - minBound
|
|
133
|
+
var max = shouldBe + 50
|
|
134
|
+
if (!(results.callsDuration > min && results.callsDuration < max)) {
|
|
135
|
+
console.error('Duration not around ' + shouldBe + '. Was ' + results.callsDuration)
|
|
136
|
+
}
|
|
137
|
+
assert(results.callsDuration > min && results.callsDuration < max)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return context
|
|
142
|
+
}
|