queueobj 7.2.3 → 8.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/README.md +2 -2
- package/app.js +107 -40
- package/lib/appenders/base.js +105 -91
- package/lib/appenders/version.js +17 -0
- package/package.json +1 -1
- package/test/package.js +1 -1
- package/test_all.js +4 -8
- package/test_bottom_one.js +4 -18
- package/test_func_all.js +1 -1
- package/test_status.js +10 -9
- package/test_sync_all.js +1 -1
- package/test_top_one.js +5 -9
- package/test_version.js +122 -0
- package/test_sync.js +0 -121
package/README.md
CHANGED
|
@@ -7,9 +7,9 @@ Included tag appenders:
|
|
|
7
7
|
* func_all - asynchronous - process custom functions to added objects.
|
|
8
8
|
* top_one - asynchronous - process only the object in the 0(zero) position of the process array.
|
|
9
9
|
* bottom_one - asynchronous - process only the object in the last position of the process array.
|
|
10
|
-
* sync - synchronous - process array objects in various ways: by items, by Ids as well as custom functions.
|
|
11
10
|
* sync_all - synchronous - queue and process all objects by items as well as custom functions.
|
|
12
11
|
* status - synchronous - queue and process all objects by status.
|
|
12
|
+
* version - synchronous - queue and process all objects by version.
|
|
13
13
|
|
|
14
14
|
Installation
|
|
15
15
|
---------
|
|
@@ -30,9 +30,9 @@ node test_all
|
|
|
30
30
|
node test_top_one
|
|
31
31
|
node test_bottom_one
|
|
32
32
|
node test_func_all
|
|
33
|
-
node test_sync
|
|
34
33
|
node test_sync_all
|
|
35
34
|
node test_status
|
|
35
|
+
node test_version
|
|
36
36
|
|
|
37
37
|
```
|
|
38
38
|
|
package/app.js
CHANGED
|
@@ -8,9 +8,9 @@ var colors = require('colors'),
|
|
|
8
8
|
func_all = require('./lib/appenders/func_all'),
|
|
9
9
|
top_one = require('./lib/appenders/top_one'),
|
|
10
10
|
bottom_one = require('./lib/appenders/bottom_one'),
|
|
11
|
-
sync = require('./lib/appenders/sync'),
|
|
12
11
|
sync_all = require('./lib/appenders/sync_all'),
|
|
13
|
-
status = require('./lib/appenders/status')
|
|
12
|
+
status = require('./lib/appenders/status'),
|
|
13
|
+
version = require('./lib/appenders/version')
|
|
14
14
|
|
|
15
15
|
class QueueObj {
|
|
16
16
|
|
|
@@ -24,8 +24,8 @@ class QueueObj {
|
|
|
24
24
|
t.top_one = null
|
|
25
25
|
t.bottom_one = null
|
|
26
26
|
t.array = null
|
|
27
|
-
t.sync = null
|
|
28
27
|
t.status = null
|
|
28
|
+
t.version = null
|
|
29
29
|
t.stats = false
|
|
30
30
|
t.sync_all = null
|
|
31
31
|
t.func_all = null
|
|
@@ -47,10 +47,10 @@ class QueueObj {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
getStats
|
|
50
|
+
getStats() {
|
|
51
51
|
return this.stats
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
getObjectById(id) {
|
|
55
55
|
let t = this, i
|
|
56
56
|
for (i = 0; i < t.objs.length; i++) {
|
|
@@ -75,13 +75,25 @@ class QueueObj {
|
|
|
75
75
|
return null
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
getObjectByVersion(version) {
|
|
79
|
+
let t = this, i
|
|
80
|
+
for (i = 0; i < t.objs.length; i++) {
|
|
81
|
+
if (typeof t.objs[i] != 'undefined' &&
|
|
82
|
+
typeof t.objs[i].version != 'undefined' &&
|
|
83
|
+
t.objs[i].version == version) {
|
|
84
|
+
return t.objs[i]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return null
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
count() {
|
|
79
|
-
return
|
|
91
|
+
return this.objs.length
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
get(num) {
|
|
83
|
-
if (num <
|
|
84
|
-
return
|
|
95
|
+
if (num < this.objs.length)
|
|
96
|
+
return this.objs[num]
|
|
85
97
|
return false
|
|
86
98
|
}
|
|
87
99
|
|
|
@@ -101,12 +113,12 @@ class QueueObj {
|
|
|
101
113
|
try {
|
|
102
114
|
var t = this
|
|
103
115
|
t.props = props
|
|
104
|
-
t.stats = (typeof props.stats != 'undefined') ?
|
|
116
|
+
t.stats = (typeof props.stats != 'undefined') ? props.stats : false;
|
|
105
117
|
if (typeof props != `undefined` &&
|
|
106
118
|
typeof props.appender != `undefined` &&
|
|
107
119
|
typeof props.appender == 'string') {
|
|
108
120
|
props.getParent = t.getParent
|
|
109
|
-
switch (props.appender) {
|
|
121
|
+
switch (props.appender) {
|
|
110
122
|
case 'all':
|
|
111
123
|
t.all = new all(props)
|
|
112
124
|
break
|
|
@@ -125,9 +137,11 @@ class QueueObj {
|
|
|
125
137
|
case 'status':
|
|
126
138
|
t.status = new status(props)
|
|
127
139
|
break
|
|
128
|
-
case '
|
|
140
|
+
case 'version':
|
|
141
|
+
t.version = new version(props)
|
|
142
|
+
break
|
|
129
143
|
case 'sync_all':
|
|
130
|
-
t.
|
|
144
|
+
t.sync_all = new sync_all(props)
|
|
131
145
|
break
|
|
132
146
|
default:
|
|
133
147
|
throw new Error(`appender(${props.appender}) not found`)
|
|
@@ -142,13 +156,55 @@ class QueueObj {
|
|
|
142
156
|
}
|
|
143
157
|
|
|
144
158
|
add(obj) {
|
|
159
|
+
var t = this
|
|
145
160
|
try {
|
|
146
|
-
|
|
161
|
+
if (t.all != null) {
|
|
162
|
+
obj.getType = (o) => {
|
|
163
|
+
return 'all'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (t.top_one != null) {
|
|
167
|
+
obj.getType = (o) => {
|
|
168
|
+
return 'top_one'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (t.bottom_one != null) {
|
|
172
|
+
t.objs = []
|
|
173
|
+
obj.getType = (o) => {
|
|
174
|
+
return 'bottom_one'
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (t.func_all != null) {
|
|
178
|
+
obj.getType = (o) => {
|
|
179
|
+
return 'func_all'
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (t.sync_all != null) {
|
|
183
|
+
obj.getType = (o) => {
|
|
184
|
+
return 'sync_all'
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (typeof obj.status != 'undefined') {
|
|
188
|
+
obj.getType = (o) => {
|
|
189
|
+
return o.status
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (typeof obj.version != 'undefined') {
|
|
193
|
+
obj.getType = (o) => {
|
|
194
|
+
return o.version
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (t.top_one != null) {
|
|
198
|
+
if (t.objs.length == 0) {
|
|
199
|
+
t.objs.push(obj)
|
|
200
|
+
}
|
|
201
|
+
return t
|
|
202
|
+
}
|
|
147
203
|
t.objs.push(obj)
|
|
148
204
|
return t
|
|
149
205
|
} catch (e) {
|
|
150
206
|
e.message = "queueObj app.js add error: " + e.message
|
|
151
|
-
console.log(e.message)
|
|
207
|
+
console.log(e.message.red)
|
|
152
208
|
throw (e)
|
|
153
209
|
}
|
|
154
210
|
}
|
|
@@ -163,57 +219,68 @@ class QueueObj {
|
|
|
163
219
|
|
|
164
220
|
process() {
|
|
165
221
|
try {
|
|
166
|
-
var t = this, pro = {
|
|
167
|
-
switch (t.props.appender) {
|
|
222
|
+
var t = this, pro = { dat_array: [] }
|
|
223
|
+
switch (t.props.appender) {
|
|
168
224
|
case 'all':
|
|
169
|
-
|
|
170
|
-
pro.items.push(i)
|
|
171
|
-
})
|
|
225
|
+
pro.dat_array.push('all')
|
|
172
226
|
t.all.await(pro)
|
|
173
227
|
return t.all.process()
|
|
174
228
|
case 'top_one':
|
|
175
|
-
pro.
|
|
229
|
+
pro.dat_array.push('top_one')
|
|
230
|
+
t.top_one.await(pro)
|
|
176
231
|
return t.top_one.process()
|
|
177
232
|
case 'bottom_one':
|
|
178
|
-
pro.
|
|
233
|
+
pro.dat_array.push('bottom_one')
|
|
234
|
+
t.bottom_one.await(pro)
|
|
179
235
|
return t.bottom_one.process()
|
|
180
236
|
case 'func_all':
|
|
181
|
-
|
|
182
|
-
pro.items.push(i)
|
|
183
|
-
})
|
|
237
|
+
pro.dat_array.push('func_all')
|
|
184
238
|
t.func_all.await(pro)
|
|
185
239
|
return t.func_all.process()
|
|
186
240
|
case 'sync':
|
|
187
|
-
|
|
241
|
+
case 'sync_all':
|
|
242
|
+
pro.dat_array.push('sync_all')
|
|
243
|
+
t.sync_all.await(pro)
|
|
244
|
+
return t.sync_all.process()
|
|
188
245
|
case 'status':
|
|
189
246
|
return t.status.process()
|
|
190
|
-
case '
|
|
191
|
-
t.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
247
|
+
case 'version':
|
|
248
|
+
return t.version.process()
|
|
249
|
+
// case 'sync_all':
|
|
250
|
+
// t.objs.map((item, i) => {
|
|
251
|
+
// pro.items.push(i)
|
|
252
|
+
// })
|
|
253
|
+
// t.sync.await(pro).then(res => {
|
|
254
|
+
// console.log(`done with ${JSON.stringify(pro)}: (${res})`.green)
|
|
255
|
+
// }, err => {
|
|
256
|
+
// console.log(`error ${JSON.stringify(pro)}: (${err})`.red)
|
|
257
|
+
// })
|
|
258
|
+
// return t.sync.process()
|
|
200
259
|
default:
|
|
201
260
|
throw new Error(`nothing to process`)
|
|
202
261
|
}
|
|
203
262
|
} catch (e) {
|
|
204
263
|
e.message = "queueObj app.js load error: " + e.message
|
|
205
|
-
console.log(e.message)
|
|
264
|
+
console.log(e.message.red)
|
|
206
265
|
throw (e)
|
|
207
266
|
}
|
|
208
267
|
}
|
|
209
268
|
|
|
210
269
|
await(props) {
|
|
270
|
+
var t = this, pro
|
|
211
271
|
try {
|
|
212
|
-
|
|
213
|
-
|
|
272
|
+
if (t.sync != null) {
|
|
273
|
+
pro = { dat_array: props.items }
|
|
214
274
|
return t.sync.await(props)
|
|
215
|
-
|
|
216
|
-
|
|
275
|
+
}
|
|
276
|
+
if (t.status != null) {
|
|
277
|
+
pro = { dat_array: props.status }
|
|
278
|
+
return t.status.await(pro)
|
|
279
|
+
}
|
|
280
|
+
if (t.version != null) {
|
|
281
|
+
pro = { dat_array: props.version }
|
|
282
|
+
return t.version.await(pro)
|
|
283
|
+
}
|
|
217
284
|
} catch (e) {
|
|
218
285
|
e.message = "queueObj app.js load error: " + e.message
|
|
219
286
|
console.log(e.message)
|
package/lib/appenders/base.js
CHANGED
|
@@ -9,12 +9,11 @@ var colors = require('colors')
|
|
|
9
9
|
exports = module.exports = class base {
|
|
10
10
|
constructor(props) {
|
|
11
11
|
let t = this
|
|
12
|
-
t.
|
|
12
|
+
t.await_array = []
|
|
13
13
|
t.resolve_array = []
|
|
14
14
|
t.reject_array = []
|
|
15
|
-
t.
|
|
16
|
-
t.
|
|
17
|
-
t.process_array_item = -1
|
|
15
|
+
t.process_objs_item = 0
|
|
16
|
+
t.process_props_item = 0
|
|
18
17
|
t.any_errors = false
|
|
19
18
|
t.getParent = props.getParent
|
|
20
19
|
t.dt_start = null
|
|
@@ -24,9 +23,10 @@ exports = module.exports = class base {
|
|
|
24
23
|
t.process_all = t.process_all.bind(this)
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
|
|
27
27
|
await(props) {
|
|
28
28
|
let t = this
|
|
29
|
-
t.
|
|
29
|
+
t.await_array.push(props)
|
|
30
30
|
return new Promise((resolve, reject) => {
|
|
31
31
|
t.resolve_array.push(resolve)
|
|
32
32
|
t.reject_array.push(reject)
|
|
@@ -35,16 +35,16 @@ exports = module.exports = class base {
|
|
|
35
35
|
|
|
36
36
|
process() {
|
|
37
37
|
let t = this
|
|
38
|
-
t.
|
|
39
|
-
t.
|
|
38
|
+
t.process_objs_item = 0
|
|
39
|
+
t.process_props_item = 0
|
|
40
|
+
t.await_item = 0
|
|
40
41
|
t.dt_start = new Date(); // start measuring time
|
|
41
|
-
t.
|
|
42
|
-
t.resolve_array = []
|
|
43
|
-
t.reject_array = []
|
|
44
|
-
t.status_props_array = []
|
|
42
|
+
// t.await_array = []
|
|
43
|
+
// t.resolve_array = []
|
|
44
|
+
// t.reject_array = []
|
|
45
|
+
// t.status_props_array = []
|
|
45
46
|
|
|
46
47
|
return new Promise((resolve, reject) => {
|
|
47
|
-
t.props_array.push({ the: 'end' })
|
|
48
48
|
t.resolve_array.push(resolve)
|
|
49
49
|
t.reject_array.push(reject)
|
|
50
50
|
t.process_all()
|
|
@@ -60,94 +60,108 @@ exports = module.exports = class base {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
process_all() {
|
|
63
|
-
let t = this, obj,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
else {
|
|
70
|
-
t.dt_end = new Date();
|
|
71
|
-
t.resolve_array[i](t.getStats())
|
|
72
|
-
}
|
|
63
|
+
let t = this, obj, pro, itm, msg, itm_type, props_type, datA
|
|
64
|
+
try {
|
|
65
|
+
try {
|
|
66
|
+
if (t.process_objs_item >= t.getParent().getObjs().length) {
|
|
67
|
+
t.await_item++
|
|
68
|
+
t.resolve_array[t.resolve_array.length - 1](t.getStats())
|
|
73
69
|
return
|
|
74
70
|
}
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
datA = t.await_array[t.await_item].dat_array
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
xItems = props.byIds
|
|
83
|
-
itm = 'byIds'
|
|
84
|
-
}
|
|
85
|
-
if (typeof props.status != 'undefined') {
|
|
86
|
-
xItems = []
|
|
87
|
-
if (t.status_props_array.length == 0) {
|
|
88
|
-
t.getParent().getObjs().map((aItem, i) => {
|
|
89
|
-
xItems.push(i)
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
itm = 'status'
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (xItems != null) {
|
|
97
|
-
xItems.map((pItem, x) => {
|
|
98
|
-
if (x == t.process_array_item) {
|
|
99
|
-
try {
|
|
100
|
-
switch (itm) {
|
|
101
|
-
case 'status':
|
|
102
|
-
case 'items':
|
|
103
|
-
obj = t.getParent().getItemToProcess(pItem)
|
|
104
|
-
break
|
|
105
|
-
case 'byIds':
|
|
106
|
-
obj = t.getParent().getObjectById(pItem);
|
|
107
|
-
break
|
|
108
|
-
}
|
|
109
|
-
} catch (e) {
|
|
110
|
-
console.log(`base error: (${e.message})`.red)
|
|
111
|
-
}
|
|
112
|
-
pro = (typeof obj == 'function') ? obj : obj.process;
|
|
113
|
-
if (itm == 'status') {
|
|
114
|
-
if (typeof pro != 'undefined' &&
|
|
115
|
-
typeof obj.status != 'undefined' &&
|
|
116
|
-
props.status.indexOf(obj.status) > -1) {
|
|
117
|
-
//do nothing
|
|
118
|
-
} else {
|
|
119
|
-
t.process_array_item++
|
|
120
|
-
if (t.process_array_item < xItems.length)
|
|
121
|
-
t.process_all()
|
|
122
|
-
return
|
|
123
|
-
}
|
|
81
|
+
datA.map((dat_item, i) => {
|
|
82
|
+
if (i == t.process_props_item) {
|
|
83
|
+
if (t.process_props_item < datA.length) {
|
|
84
|
+
if ((t.await_item) >= t.await_array.length) {
|
|
85
|
+
t.resolve_array[t.resolve_array.length - 1](t.getStats())
|
|
86
|
+
return
|
|
124
87
|
}
|
|
88
|
+
t.getParent().getObjs().map((pItem, x) => {
|
|
89
|
+
if (x == t.process_objs_item) {
|
|
90
|
+
try {
|
|
91
|
+
obj = t.getParent().getItemToProcess(x)
|
|
92
|
+
} catch (e) {
|
|
93
|
+
e.message = `base error: (${e.message})`
|
|
94
|
+
throw e
|
|
95
|
+
}
|
|
96
|
+
if (typeof obj != 'undefined' && typeof obj.getType != 'function') {
|
|
97
|
+
obj.getType = (o) => { return t.aname }
|
|
98
|
+
}
|
|
99
|
+
if (obj.getType(obj) == dat_item) {
|
|
100
|
+
try {
|
|
101
|
+
pro = (typeof obj == 'function') ? obj : obj.process;
|
|
102
|
+
} catch (e) {
|
|
103
|
+
console.log(`pro error: (${e.message})`.red)
|
|
104
|
+
throw e
|
|
105
|
+
}
|
|
125
106
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
pro((obj_props) => {
|
|
108
|
+
try {
|
|
109
|
+
|
|
110
|
+
if (typeof obj_props != 'undefined') {
|
|
111
|
+
if (typeof obj_props.error != 'undefined' &&
|
|
112
|
+
typeof obj_props.error.msg != 'undefined' &&
|
|
113
|
+
typeof obj_props.error.msg == 'string') {
|
|
114
|
+
msg = `error: ${obj_props.error.msg}`
|
|
115
|
+
msg += (typeof obj.id != 'undefined') ? ` id(${obj.id})` : ``;
|
|
116
|
+
t.any_errors = true
|
|
117
|
+
t.reject_array[t.process_props_item](msg)
|
|
118
|
+
} else {
|
|
119
|
+
console.log(`${JSON.stringify(obj_props)}`.green)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
t.process_objs_item++
|
|
123
|
+
if (t.process_props_item < datA.length) {
|
|
124
|
+
t.process_all()
|
|
125
|
+
} else {
|
|
126
|
+
t.dt_end = new Date();
|
|
127
|
+
t.resolve_array[t.process_props_item - 1](t.getStats())
|
|
128
|
+
t.process_props_item = 0
|
|
129
|
+
t.process_objs_item = 0
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.log(`proessing error: (${e.message})`.red)
|
|
133
|
+
throw e
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
} else {
|
|
137
|
+
t.process_objs_item++
|
|
138
|
+
if (t.process_objs_item >= t.getParent().getObjs().length) {
|
|
139
|
+
t.resolve_array[t.resolve_array.length - 1](t.getStats())
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
if (t.process_objs_item >= t.getParent().getObjs().length) {
|
|
144
|
+
t.process_objs_item = 0
|
|
145
|
+
t.process_props_item++
|
|
146
|
+
if (t.process_props_item >= datA.length) {
|
|
147
|
+
t.await_item++
|
|
148
|
+
t.process_props_item = 0
|
|
149
|
+
if (t.await_item <= t.await_array.length)
|
|
150
|
+
t.process_all()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
144
153
|
}
|
|
145
154
|
})
|
|
146
155
|
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
} catch (e) {
|
|
159
|
+
e.message = `await error: ${e.message}`
|
|
160
|
+
throw e
|
|
149
161
|
}
|
|
150
|
-
})
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.log(`process_all error: ${e.message}`.red)
|
|
164
|
+
}
|
|
151
165
|
}
|
|
152
166
|
}
|
|
153
167
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2021-03-22
|
|
4
|
+
* lib/appenders/status.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var base = require('./base.js')
|
|
8
|
+
|
|
9
|
+
exports = module.exports = class version extends base {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props)
|
|
12
|
+
var t = this
|
|
13
|
+
t.aname = 'version'
|
|
14
|
+
t.pro_types = ['version']
|
|
15
|
+
return t
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
package/test/package.js
CHANGED
package/test_all.js
CHANGED
|
@@ -4,8 +4,7 @@ var queue = require("./app.js");
|
|
|
4
4
|
|
|
5
5
|
class test1 {
|
|
6
6
|
process(callback){
|
|
7
|
-
|
|
8
|
-
callback()
|
|
7
|
+
callback({success: `processing all test1`})
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -15,22 +14,19 @@ class test2 {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
process(callback){
|
|
18
|
-
|
|
19
|
-
callback()
|
|
17
|
+
callback({success: `processing all test2`})
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
class test3 {
|
|
24
22
|
process(callback){
|
|
25
|
-
|
|
26
|
-
callback()
|
|
23
|
+
callback({success: `processing all test3`})
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
class test4 {
|
|
31
28
|
process(callback){
|
|
32
|
-
|
|
33
|
-
callback()
|
|
29
|
+
callback({success: `processing all test4`})
|
|
34
30
|
}
|
|
35
31
|
}
|
|
36
32
|
|
package/test_bottom_one.js
CHANGED
|
@@ -23,24 +23,10 @@ class test3 {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
let qObj = new queue(), props = { appender: 'bottom_one' }
|
|
26
|
+
let qObj = new queue(), props = { appender: 'bottom_one', stats: true}
|
|
27
27
|
|
|
28
|
-
qObj.load(props).add(new test1()).add(new test2()).add(new test3())
|
|
29
|
-
|
|
30
|
-
qObj.process().then(res => {
|
|
31
|
-
console.log(`done with 3rd obj`.green)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
qObj.process().then(res => {
|
|
35
|
-
console.log(`done with 2nd obj`.green)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
qObj.process().then(res => {
|
|
39
|
-
console.log(`done with 1st obj`.green)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
qObj.process().then(res => {
|
|
43
|
-
console.log(`done with 1st obj`.green)
|
|
28
|
+
qObj.load(props).add(new test1()).add(new test2(qObj)).add(new test3()).process({}).then(res => {
|
|
29
|
+
console.log(res)
|
|
44
30
|
}, err => {
|
|
45
|
-
|
|
31
|
+
console.log(`errors with bottom item processing: (${err})`.red)
|
|
46
32
|
})
|
package/test_func_all.js
CHANGED
package/test_status.js
CHANGED
|
@@ -36,9 +36,9 @@ class test2 {
|
|
|
36
36
|
let t = this, msg = `some kinda problem here`
|
|
37
37
|
console.log(`processing test2`.cyan)
|
|
38
38
|
t.status = "error"
|
|
39
|
-
callback({error: {msg: msg}}) //this will show errors
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
// callback({error: {msg: msg}}) //this will show errors
|
|
40
|
+
t.status = "done"
|
|
41
|
+
callback() //this will show no errors
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
ping() {
|
|
@@ -56,12 +56,10 @@ class test3 {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
process(callback) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
callback()
|
|
64
|
-
}, 2000)
|
|
59
|
+
console.log(`processing test3`.cyan)
|
|
60
|
+
console.log(`some async process`)
|
|
61
|
+
this.status = "done"
|
|
62
|
+
callback()
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
|
|
@@ -70,10 +68,13 @@ class test4 {
|
|
|
70
68
|
let t = this
|
|
71
69
|
t.id = 400
|
|
72
70
|
t.status = "new"
|
|
71
|
+
|
|
72
|
+
t.process = t.process.bind(t)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
process(callback) {
|
|
76
76
|
console.log(`processing test4`.cyan)
|
|
77
|
+
this.status = "done"
|
|
77
78
|
callback()
|
|
78
79
|
}
|
|
79
80
|
}
|
package/test_sync_all.js
CHANGED
|
@@ -69,7 +69,7 @@ let qObj = new queue(), props = { appender: 'sync_all' }
|
|
|
69
69
|
qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(tst4.custom_function)
|
|
70
70
|
|
|
71
71
|
qObj.process().then(res => {
|
|
72
|
-
console.log(`done with all sync processing: (${res})`.bold.italic.
|
|
72
|
+
console.log(`done with all sync processing: (${res})`.bold.italic.blue)
|
|
73
73
|
}, err => {
|
|
74
74
|
console.log(`errors with all sync processing: (${err})`.red)
|
|
75
75
|
})
|
package/test_top_one.js
CHANGED
|
@@ -23,14 +23,10 @@ class test3 {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
let qObj = new queue(), props = { appender: 'top_one'}
|
|
26
|
+
let qObj = new queue(), props = { appender: 'top_one', stats: true}
|
|
27
27
|
|
|
28
|
-
qObj.load(props).add(new test1()).add(new test2()).add(new test3())
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.log(`
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
qObj.process().then(res => {
|
|
35
|
-
console.log(`done with 2nd obj`.green)
|
|
28
|
+
qObj.load(props).add(new test1()).add(new test2(qObj)).add(new test3()).process({}).then(res => {
|
|
29
|
+
console.log(res)
|
|
30
|
+
}, err => {
|
|
31
|
+
console.log(`errors with top item processing: (${err})`.red)
|
|
36
32
|
})
|
package/test_version.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2021-03-22
|
|
4
|
+
* test_status.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var colors = require('colors')
|
|
8
|
+
var queue = require("./app.js");
|
|
9
|
+
|
|
10
|
+
class test1 {
|
|
11
|
+
constructor() {
|
|
12
|
+
let t = this
|
|
13
|
+
t.id = 100
|
|
14
|
+
t.version = "dev"
|
|
15
|
+
|
|
16
|
+
t.process = t.process.bind(t)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
process(callback) {
|
|
20
|
+
let t = this
|
|
21
|
+
console.log(`processing test1 version(${t.version})`.cyan)
|
|
22
|
+
this.status = "done"
|
|
23
|
+
callback()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class test2 {
|
|
28
|
+
constructor() {
|
|
29
|
+
let t = this
|
|
30
|
+
t.id = 200
|
|
31
|
+
t.version = "dev"
|
|
32
|
+
|
|
33
|
+
t.process = t.process.bind(t)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
process(callback) {
|
|
37
|
+
let t = this, msg = `some kinda error is detected here`
|
|
38
|
+
console.log(`processing test2 version(${t.version})`.cyan)
|
|
39
|
+
// callback({error: {msg: msg}}) //this will show errors
|
|
40
|
+
callback() //this will have no errors
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ping() {
|
|
44
|
+
console.log('hello from test2'.rainbow)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class test3 {
|
|
49
|
+
constructor() {
|
|
50
|
+
let t = this
|
|
51
|
+
t.id = 300
|
|
52
|
+
t.version = "test"
|
|
53
|
+
|
|
54
|
+
t.process = t.process.bind(t)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
process(callback) {
|
|
58
|
+
let t = this
|
|
59
|
+
console.log(`processing test3 version(${t.version})`.cyan)
|
|
60
|
+
console.log(`some async process`)
|
|
61
|
+
callback()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class test4 {
|
|
66
|
+
constructor() {
|
|
67
|
+
let t = this
|
|
68
|
+
t.id = 400
|
|
69
|
+
t.version = "prod"
|
|
70
|
+
|
|
71
|
+
t.process = t.process.bind(t)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
process(callback) {
|
|
75
|
+
let t = this
|
|
76
|
+
console.log(`processing test4 version(${t.version})`.cyan)
|
|
77
|
+
callback()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
class test5 {
|
|
82
|
+
constructor() {
|
|
83
|
+
let t = this
|
|
84
|
+
t.id = 500
|
|
85
|
+
t.version = "v1234"
|
|
86
|
+
|
|
87
|
+
t.process = t.process.bind(t)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
process(callback) {
|
|
91
|
+
let t = this
|
|
92
|
+
console.log(`processing test5 version(${t.version})`.cyan)
|
|
93
|
+
callback()
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let qObj = new queue(), props = { appender: 'version' }
|
|
97
|
+
|
|
98
|
+
qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(new test4()).add(new test5())
|
|
99
|
+
|
|
100
|
+
qObj.await({ version: ['dev', 'test'] }).then(res => {
|
|
101
|
+
console.log(`1) done with version['dev', 'test']: (${res})`.green)
|
|
102
|
+
}, err => {
|
|
103
|
+
console.log(`1) error['dev', 'test']: (${err})`.red)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
qObj.await({ version: ['prod'] }).then(res => {
|
|
107
|
+
console.log(`2) done with version['prod']: (${res})`.green)
|
|
108
|
+
}, err => {
|
|
109
|
+
console.log(`2) error['prod']: (${err})`.red)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
qObj.await({ version: ['v1234'] }).then(res => {
|
|
113
|
+
console.log(`3) done with version['v1234']: (${res})`.green)
|
|
114
|
+
}, err => {
|
|
115
|
+
console.log(`3) error['v1234']: (${err})`.red)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
qObj.process().then(res => {
|
|
119
|
+
console.log(`4) done with version synchronous processing: (${res})`.bold.italic.blue)
|
|
120
|
+
}, err => {
|
|
121
|
+
console.log(`4) errors with version synchronous processing: (${err})`.red)
|
|
122
|
+
})
|
package/test_sync.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
-
* @since 2021-03-22
|
|
4
|
-
* test_sync.js
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var colors = require('colors')
|
|
8
|
-
var queue = require("./app.js");
|
|
9
|
-
|
|
10
|
-
class test1 {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.id = 100
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
process(callback) {
|
|
16
|
-
console.log(`processing test1`.cyan)
|
|
17
|
-
callback()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class test2 {
|
|
22
|
-
constructor() {
|
|
23
|
-
this.id = 200
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
process(callback) {
|
|
27
|
-
let msg = `some kinda problem here`
|
|
28
|
-
console.log(`processing test2`.cyan)
|
|
29
|
-
//callback({error: {msg: msg}}) //this will show errors
|
|
30
|
-
callback() //this will show no errors
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ping() {
|
|
34
|
-
console.log('hello from test2'.rainbow)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class test3 {
|
|
39
|
-
constructor() {
|
|
40
|
-
this.id = 300
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
process(callback) {
|
|
44
|
-
setTimeout(()=>{
|
|
45
|
-
console.log(`processing test3`.cyan)
|
|
46
|
-
console.log(`some async process`)
|
|
47
|
-
callback()
|
|
48
|
-
}, 2000)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class test4 {
|
|
53
|
-
constructor() {
|
|
54
|
-
let t = this
|
|
55
|
-
t.id = 400
|
|
56
|
-
t.custom_function = t.custom_function.bind(this)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
custom_function(callback) {
|
|
60
|
-
let msg = `custom func problem here id(${this.id})`
|
|
61
|
-
console.log(`processing test4`.cyan)
|
|
62
|
-
//callback({error: {msg: msg}}) //this will show errors
|
|
63
|
-
callback() //this will show no errors
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
let tst4 = new test4()
|
|
67
|
-
let qObj = new queue(), props = { appender: 'sync', stats: false }
|
|
68
|
-
|
|
69
|
-
qObj.load(props).add(new test1()).add(new test2()).add(new test3()).add(tst4.custom_function)
|
|
70
|
-
|
|
71
|
-
qObj.await({ items: [0, 1] }).then(res => {
|
|
72
|
-
console.log(`1) done with items[0,1]: (${res})`.green)
|
|
73
|
-
}, err => {
|
|
74
|
-
console.log(`1) error[0, 1]: (${err})`.red)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
qObj.await({ items: [1, 2] }).then(res => {
|
|
78
|
-
console.log(`2) done with items[1,2]: (${res})`.green)
|
|
79
|
-
}, err => {
|
|
80
|
-
console.log(`2) error[1,2]: (${err})`.red)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
qObj.await({ items: [2, 1, 2] }).then(res => {
|
|
84
|
-
console.log(`3) done with items[2,1,2]: (${res})`.green)
|
|
85
|
-
}, err => {
|
|
86
|
-
console.log(`3) error[2, 1, 2]: (${err})`.red)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
qObj.await({ items: [2, 3] }).then(res => {
|
|
90
|
-
console.log(`4) done with item[2, 3]: (${res})`.green)
|
|
91
|
-
}, err => {
|
|
92
|
-
console.log(`4) error[2, 3]: (${err})`.red)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
qObj.await({ items: [0] }).then(res => {
|
|
96
|
-
console.log(`5) done with item[0]: (${res})`.green)
|
|
97
|
-
}, err => {
|
|
98
|
-
console.log(err.red)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
qObj.getObjectById(200).ping()
|
|
102
|
-
|
|
103
|
-
qObj.await({ byIds: [300, 200, 100] }).then(res => {
|
|
104
|
-
console.log(`6) done with byId: [300, 200, 100] (${res})`.bold.italic.underline.yellow)
|
|
105
|
-
}, err => {
|
|
106
|
-
console.log(`6) error[300, 200, 100]: (${err})`.red)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
qObj.await({ byIds: [100, 300] }).then(res => {
|
|
110
|
-
console.log(`7) done with byId: [100, 300] (${res})`.bold.italic.underline.yellow)
|
|
111
|
-
}, err => {
|
|
112
|
-
console.log(`7) error[100, 300]: (${err})`.red)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
qObj.process().then(res => {
|
|
116
|
-
console.log(`8) done with all sync processing: (${res})`.bold.italic.white)
|
|
117
|
-
}, err => {
|
|
118
|
-
console.log(`8) errors with all sync processing: (${err})`.red)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
|