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.

Files changed (99) hide show
  1. package/.babelrc.es5 +5 -0
  2. package/.babelrc.lib +9 -0
  3. package/.env +2 -0
  4. package/.travis.yml +25 -0
  5. package/LICENSE +20 -0
  6. package/README.md +474 -2
  7. package/bower.json +30 -0
  8. package/es5.js +5064 -0
  9. package/lib/Batcher.js +1 -0
  10. package/lib/DLList.js +1 -0
  11. package/lib/Events.js +1 -0
  12. package/lib/Group.js +1 -0
  13. package/lib/IORedisConnection.js +1 -0
  14. package/lib/Job.js +1 -0
  15. package/lib/LocalDatastore.js +1 -0
  16. package/lib/Queues.js +1 -0
  17. package/lib/RedisConnection.js +1 -0
  18. package/lib/RedisDatastore.js +1 -0
  19. package/lib/Scripts.js +1 -0
  20. package/lib/States.js +1 -0
  21. package/lib/Sync.js +1 -0
  22. package/lib/Taskpace.js +1 -0
  23. package/lib/TaskpaceError.js +1 -0
  24. package/lib/common.js +1 -0
  25. package/lib/es5.js +1 -0
  26. package/lib/index.js +1 -0
  27. package/lib/limit.js +1 -0
  28. package/lib/lua.json +24 -0
  29. package/lib/parser.js +1 -0
  30. package/lib/redis.js +1 -0
  31. package/lib/validate.js +1 -0
  32. package/lib/version.json +1 -0
  33. package/light.js +1524 -0
  34. package/package.json +53 -4
  35. package/rollup.config.es5.js +34 -0
  36. package/rollup.config.light.js +44 -0
  37. package/scripts/assemble_lua.js +25 -0
  38. package/scripts/build.sh +81 -0
  39. package/scripts/test_all.sh +20 -0
  40. package/scripts/version.js +3 -0
  41. package/src/Batcher.coffee +39 -0
  42. package/src/DLList.coffee +38 -0
  43. package/src/Events.coffee +38 -0
  44. package/src/Group.coffee +80 -0
  45. package/src/IORedisConnection.coffee +84 -0
  46. package/src/Job.coffee +98 -0
  47. package/src/LocalDatastore.coffee +140 -0
  48. package/src/Queues.coffee +28 -0
  49. package/src/RedisConnection.coffee +91 -0
  50. package/src/RedisDatastore.coffee +158 -0
  51. package/src/Scripts.coffee +151 -0
  52. package/src/States.coffee +43 -0
  53. package/src/Sync.coffee +28 -0
  54. package/src/Taskpace.coffee +298 -0
  55. package/src/TaskpaceError.coffee +3 -0
  56. package/src/es5.coffee +3 -0
  57. package/src/index.coffee +1 -0
  58. package/src/parser.coffee +10 -0
  59. package/src/redis/blacklist_client.lua +8 -0
  60. package/src/redis/check.lua +6 -0
  61. package/src/redis/conditions_check.lua +3 -0
  62. package/src/redis/current_reservoir.lua +1 -0
  63. package/src/redis/done.lua +3 -0
  64. package/src/redis/free.lua +5 -0
  65. package/src/redis/get_time.lua +7 -0
  66. package/src/redis/group_check.lua +1 -0
  67. package/src/redis/heartbeat.lua +1 -0
  68. package/src/redis/increment_reservoir.lua +10 -0
  69. package/src/redis/init.lua +105 -0
  70. package/src/redis/process_tick.lua +214 -0
  71. package/src/redis/queued.lua +10 -0
  72. package/src/redis/refresh_expiration.lua +11 -0
  73. package/src/redis/refs.lua +13 -0
  74. package/src/redis/register.lua +51 -0
  75. package/src/redis/register_client.lua +12 -0
  76. package/src/redis/running.lua +1 -0
  77. package/src/redis/submit.lua +74 -0
  78. package/src/redis/update_settings.lua +14 -0
  79. package/src/redis/validate_client.lua +5 -0
  80. package/src/redis/validate_keys.lua +3 -0
  81. package/taskpace.d.ts +629 -0
  82. package/taskpace.d.ts.ejs +588 -0
  83. package/test/DLList.js +148 -0
  84. package/test/batcher.js +209 -0
  85. package/test/cluster.js +1549 -0
  86. package/test/context.js +142 -0
  87. package/test/general.js +867 -0
  88. package/test/group.js +255 -0
  89. package/test/ioredis.js +135 -0
  90. package/test/node_redis.js +100 -0
  91. package/test/priority.js +184 -0
  92. package/test/promises.js +202 -0
  93. package/test/retries.js +237 -0
  94. package/test/spawn/increaseKeepAlive.js +17 -0
  95. package/test/spawn/refreshKeepAlive.js +17 -0
  96. package/test/states.js +103 -0
  97. package/test/stop.js +208 -0
  98. package/test/taskpace.js +7 -0
  99. package/test.ts +335 -0
@@ -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
+ }