file-obj-queue 2.0.5 → 3.0.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.
- package/.github/workflows/{github-actions-demo.yml → github-actions.yml} +1 -1
- package/.github/workflows/node.js.yml +1 -0
- package/LICENSE +1 -1
- package/README.md +132 -7
- package/app.js +155 -40
- package/lib/appenders/all.js +17 -0
- package/lib/appenders/base.js +189 -0
- package/lib/appenders/bottom_one.js +17 -0
- package/lib/appenders/func_all.js +17 -0
- package/lib/appenders/name.js +17 -0
- package/lib/appenders/status.js +17 -0
- package/lib/appenders/sync.js +17 -0
- package/lib/appenders/sync_all.js +17 -0
- package/lib/appenders/top_one.js +17 -0
- package/lib/appenders/version.js +17 -0
- package/package.json +24 -3
- package/test/app.js +5 -1
- package/test/package.js +25 -3
- package/tests/all.js +85 -0
- package/tests/appenders/all.js +1 -1
- package/tests/appenders/base.js +1 -1
- package/tests/appenders/bottom_one.js +1 -1
- package/tests/appenders/func_all.js +1 -1
- package/tests/appenders/sync.js +1 -1
- package/tests/appenders/sync_all.js +1 -1
- package/tests/appenders/top_one.js +1 -1
- package/tests/appenders/version.js +1 -1
- package/tests/bottom_one.js +86 -0
- package/tests/files.js +50 -32
- package/tests/func_all.js +94 -0
- package/tests/json_all.js +107 -0
- package/tests/json_bottom_one.js +108 -0
- package/tests/json_func_all.js +109 -0
- package/tests/json_name_matching.js +109 -0
- package/tests/json_name_non_matching.js +109 -0
- package/tests/json_status_matching.js +110 -0
- package/tests/json_status_non_matching.js +110 -0
- package/tests/json_top_one.js +108 -0
- package/tests/json_version_matching.js +110 -0
- package/tests/json_version_non_matching.js +110 -0
- package/tests/name_matching.js +90 -0
- package/tests/name_non_matching.js +90 -0
- package/tests/status_matching.js +90 -0
- package/tests/status_non_matching.js +90 -0
- package/tests/top_one.js +85 -0
- package/tests/version_matching.js +90 -0
- package/tests/version_non_matching.js +90 -0
- package/base_queue/app.js +0 -146
- package/base_queue/appenders/base.js +0 -77
- package/base_queue/appenders/json_all.js +0 -70
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
[](https://www.npmjs.org/package/queueobj)
|
|
2
|
+
[](https://github.com/jman717/queueobj/blob/master/LICENSE)
|
|
3
|
+
[](https://github.com/jman717/QueueObj/blob/main/.github/workflows/github-actions.yml)
|
|
4
|
+
[](https://github.com/jman717/QueueObj/actions/workflows/node.js.yml)
|
|
5
5
|
|
|
6
|
-
[](https://nodei.co/npm/queueobj/)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Queue javascript objects dynamically then process the queue according to the appender. All appenders are handled synchronously.
|
|
9
|
+
|
|
10
|
+
Included tag appenders:
|
|
11
|
+
|
|
12
|
+
* files - See if inputed files exists.
|
|
13
|
+
* all - process all added objects.
|
|
14
|
+
* top_one - process only the object in the 0(zero) position of the process array.
|
|
15
|
+
* bottom_one - process only the object in the last position of the process array.
|
|
16
|
+
* func_all - process custom function names in created objects. Custom processing names can be used in any appender, this is just one example.
|
|
17
|
+
* status - queue and process all objects by status.
|
|
18
|
+
* name - queue and process all objects by name.
|
|
19
|
+
* version - queue and process all objects by version.
|
|
20
|
+
|
|
21
|
+
* json_all - process a class object per json input array variables.
|
|
22
|
+
* json_top_one - process a class object per the first json input array variable.
|
|
23
|
+
* json_bottom_one - process a class object per the last json input array variable.
|
|
24
|
+
* json_func_all - process custom function names in created objects. Custom processing names can be used in any json appender, this is just one example.
|
|
25
|
+
* json_status - queue and process all objects by status.
|
|
26
|
+
* json_name - queue and process all objects by name.
|
|
27
|
+
* json_version - queue and process all objects by version.
|
|
9
28
|
|
|
10
29
|
Mocha Test
|
|
11
30
|
---------
|
|
@@ -17,5 +36,111 @@ General Setup Test
|
|
|
17
36
|
---------
|
|
18
37
|
```
|
|
19
38
|
npm run test_files
|
|
39
|
+
npm run test_all
|
|
40
|
+
npm run test_top_one
|
|
41
|
+
npm run test_bottom_one
|
|
42
|
+
npm run test_func_all
|
|
43
|
+
npm run test_status_matching
|
|
44
|
+
npm run test_status_non_matching
|
|
45
|
+
npm run test_name_matching
|
|
46
|
+
npm run test_name_non_matching
|
|
47
|
+
npm run test_version_matching
|
|
48
|
+
npm run test_version_non_matching
|
|
49
|
+
npm run test_json_all
|
|
50
|
+
npm run test_json_top_one
|
|
51
|
+
npm run test_json_bottom_one
|
|
52
|
+
npm run test_json_func_all
|
|
53
|
+
npm run test_json_status_matching
|
|
54
|
+
npm run test_json_status_non_matching
|
|
55
|
+
npm run test_json_version_matching
|
|
56
|
+
npm run test_json_version_non_matching
|
|
57
|
+
npm run test_json_name_matching
|
|
58
|
+
npm run test_json_name_non_matching
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Usage
|
|
63
|
+
---------
|
|
64
|
+
```js
|
|
65
|
+
|
|
66
|
+
var queue = require("queueobj");
|
|
67
|
+
|
|
68
|
+
var tst1 = class test1 {
|
|
69
|
+
constructor(props) {
|
|
70
|
+
let t = this, fname = "test_all.test1.constructor"
|
|
71
|
+
t.log = props.log
|
|
72
|
+
t.id = props.id
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
process(callback) {
|
|
76
|
+
let t = this, fname = "test_all.test1.process"
|
|
77
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
78
|
+
callback({ success: { msg: `processing all test1` } })
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var tst2 = class test2 {
|
|
83
|
+
constructor(props) {
|
|
84
|
+
let t = this, fname = "test_all.test2.constructor"
|
|
85
|
+
t.log = props.log
|
|
86
|
+
t.id = props.id
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
process(callback) {
|
|
90
|
+
let t = this, fname = "test_all.test2.process"
|
|
91
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
callback({ success: { msg: `processing all test2` } })
|
|
94
|
+
}, 4000)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var tst3 = class test3 {
|
|
99
|
+
constructor(props) {
|
|
100
|
+
let t = this, fname = "test_all.test3.constructor"
|
|
101
|
+
t.log = props.log
|
|
102
|
+
t.id = props.id
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
process(callback) {
|
|
106
|
+
let t = this, fname = "test_all.test3.process"
|
|
107
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
108
|
+
// callback({success: { msg: `processing all test3` }})
|
|
109
|
+
callback({ error: { msg: `there is some problem thrown here on test3` } })
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var tst4 = class test4 {
|
|
114
|
+
constructor(props) {
|
|
115
|
+
let t = this, fname = "test_all.test4.constructor"
|
|
116
|
+
t.log = props.log
|
|
117
|
+
t.id = props.id
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
process(callback) {
|
|
122
|
+
let t = this, fname = "test_all.test4.process"
|
|
123
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
124
|
+
callback({ success: { msg: `processing all test4` } })
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var qObj = new queue()
|
|
129
|
+
|
|
130
|
+
qObj.init().process({
|
|
131
|
+
appender: "all",
|
|
132
|
+
exclude_logMsg: ["debug"], /* example ["debug", "info"] */
|
|
133
|
+
process_objects: [tst1, tst2, tst3, tst4]
|
|
134
|
+
}).then((success) => {
|
|
135
|
+
qObj.logMsg({ msg: `test success: {msg: "all objects processed with no errors"}`.success.italic.bold, type: "success" })
|
|
136
|
+
}, (error) => {
|
|
137
|
+
if (typeof error == "string") {
|
|
138
|
+
qObj.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
139
|
+
} else {
|
|
140
|
+
let add_s = (error.error_count > 1) ? 's' : ''
|
|
141
|
+
qObj.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
```
|
|
20
146
|
|
|
21
|
-
```
|
package/app.js
CHANGED
|
@@ -3,70 +3,185 @@
|
|
|
3
3
|
* Main processing app
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
let
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
let base_queue = require("base-queue"),
|
|
7
|
+
log_queue = require("log-queue"),
|
|
8
|
+
fs = require('fs'),
|
|
9
|
+
validPath = require('valid-path')
|
|
10
|
+
|
|
11
|
+
const { memoryUsage } = require('process')
|
|
12
|
+
|
|
13
|
+
var log_data = [
|
|
14
|
+
{ props: { id: 100, name: "console_basic", absolute_path: __filename, check: true } }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var log_object = class log_obj {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
let t = this
|
|
21
|
+
t.id = props.id
|
|
22
|
+
t.log = props.log
|
|
23
|
+
t.name = props.name
|
|
24
|
+
t.path = props.relative_path
|
|
25
|
+
t.absolute_path = props.absolute_path
|
|
26
|
+
t.status = 'init'
|
|
27
|
+
t.errors = false
|
|
28
|
+
t.error_msg = 'none'
|
|
29
|
+
|
|
30
|
+
t.process = t.process.bind(t)
|
|
31
|
+
t.do_checks = t.do_checks.bind(t)
|
|
32
|
+
|
|
33
|
+
if (props.check) {
|
|
34
|
+
t.do_checks()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return t
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
do_checks() {
|
|
41
|
+
let t = this, path_to_check,
|
|
42
|
+
last_item = t.absolute_path.split("\\").pop(),
|
|
43
|
+
check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('../')
|
|
44
|
+
|
|
45
|
+
check_file = check_file.replace(/\\/g, "/");
|
|
46
|
+
path_to_check = validPath(t.path);
|
|
47
|
+
|
|
48
|
+
if (!path_to_check.valid) {
|
|
49
|
+
t.errors = true
|
|
50
|
+
t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// check_path.map((dat, i) => {
|
|
54
|
+
// if (/^[a-zA-Z._]+$/.test(dat)) {
|
|
55
|
+
// if (dat != '.' || dat != '..')
|
|
56
|
+
// check_file += dat + '/'
|
|
57
|
+
// }
|
|
58
|
+
// })
|
|
59
|
+
// check_file = check_file.slice(0, -1)
|
|
60
|
+
check_file += check_path[1]
|
|
61
|
+
check_file += `${t.name}.js`
|
|
62
|
+
try {
|
|
63
|
+
if (!fs.existsSync(check_file)) {
|
|
64
|
+
t.errors = true
|
|
65
|
+
t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
e.message = "file_obj do_checks error: " + e.message
|
|
69
|
+
throw (e)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
process(callback) {
|
|
74
|
+
let t = this
|
|
75
|
+
if (t.errors)
|
|
76
|
+
callback({ error: {msg: t.error_msg} })
|
|
77
|
+
else {
|
|
78
|
+
callback({ success: {msg: `id = ${t.id} name(${t.name}) success`} })
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
exports = module.exports = class QueueObj {
|
|
24
84
|
constructor() {
|
|
85
|
+
var t = this, fname = 'QueueObj.constructor'
|
|
25
86
|
try {
|
|
26
|
-
|
|
27
|
-
t.
|
|
28
|
-
t.
|
|
87
|
+
t.promise = null
|
|
88
|
+
t.resolve = null
|
|
89
|
+
t.reject = null
|
|
90
|
+
t.promise_2q = null
|
|
91
|
+
t.resolve_2q = null
|
|
92
|
+
t.reject_2q = null
|
|
29
93
|
t.successMsg = ''
|
|
94
|
+
t.log_queue = null
|
|
30
95
|
|
|
31
96
|
t.logMsg = t.logMsg.bind(t)
|
|
97
|
+
t.init = t.init.bind(t)
|
|
32
98
|
t.process = t.process.bind(t)
|
|
33
99
|
t.getFileObject = t.getFileObject.bind(t)
|
|
34
100
|
|
|
35
|
-
t.logMsg(`
|
|
101
|
+
// t.logMsg(`QueueObj.constructor`.debug)
|
|
36
102
|
|
|
37
103
|
return t
|
|
38
104
|
} catch (e) {
|
|
39
|
-
e.message = `
|
|
40
|
-
|
|
105
|
+
e.message = `QueueObj app.js constructor error: ${e.message}`.error
|
|
106
|
+
console.log(e.message)
|
|
41
107
|
}
|
|
42
108
|
}
|
|
43
109
|
|
|
44
|
-
|
|
45
|
-
|
|
110
|
+
init() {
|
|
111
|
+
var t = this, fname = `QueueObj.init`
|
|
112
|
+
try {
|
|
113
|
+
t.promise = new Promise((resolve, reject) => {
|
|
114
|
+
t.resolve = resolve
|
|
115
|
+
t.reject = reject
|
|
116
|
+
})
|
|
117
|
+
t.promise_2q= new Promise((resolve, reject) => {
|
|
118
|
+
t.resolve_2q = resolve
|
|
119
|
+
t.reject_2q = reject
|
|
120
|
+
})
|
|
121
|
+
return t
|
|
122
|
+
} catch (e) {
|
|
123
|
+
t.logMsg({ msg: `${fname} error: (${e.message})`.error, type: 'error' })
|
|
124
|
+
// e.message = `QueueObj app.js constructor error: ${e.message}`.error
|
|
125
|
+
// console.log(e.message)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
46
128
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
t.app_reject = reject
|
|
129
|
+
process(props = {}) {
|
|
130
|
+
let t = this, fname = `app.process`
|
|
50
131
|
|
|
51
|
-
|
|
52
|
-
|
|
132
|
+
// if (typeof props.data_to_process_array == 'undefined')
|
|
133
|
+
// t.reject('base_queue no props.data_to_process_array')
|
|
53
134
|
|
|
54
|
-
|
|
55
|
-
|
|
135
|
+
if (typeof props.appender == 'undefined')
|
|
136
|
+
t.reject('base_queue no props.appender')
|
|
56
137
|
|
|
57
|
-
|
|
58
|
-
|
|
138
|
+
if (typeof props.process_objects == 'undefined')
|
|
139
|
+
t.reject(`props.process_objects not defined`)
|
|
59
140
|
|
|
60
|
-
|
|
61
|
-
t.
|
|
62
|
-
|
|
141
|
+
try {
|
|
142
|
+
t.log_queue = new log_queue({
|
|
143
|
+
parent: t,
|
|
144
|
+
relative_path: "../base_queue/appenders/log/",
|
|
145
|
+
exclude_logMsg: props.exclude_logMsg,
|
|
146
|
+
resolve: t.resolve,
|
|
147
|
+
reject: t.reject
|
|
148
|
+
}).init({
|
|
149
|
+
appender: "console_basic",
|
|
150
|
+
process_objects: [log_object],
|
|
151
|
+
data_to_process_array: log_data
|
|
152
|
+
})
|
|
153
|
+
t.base_queue = new base_queue({
|
|
154
|
+
parent: t,
|
|
155
|
+
relative_path: "./appenders/",
|
|
156
|
+
logMsg: t.logMsg,
|
|
157
|
+
resolve: t.resolve_2q,
|
|
158
|
+
reject: t.reject_2q
|
|
159
|
+
}).load(props).process()
|
|
160
|
+
return t.promise_2q
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.log(`${fname} error: (${e.message})`)
|
|
163
|
+
}
|
|
63
164
|
}
|
|
64
165
|
|
|
65
166
|
getFileObject() {
|
|
66
167
|
return this.qJson.get_class_obj_array()
|
|
67
168
|
}
|
|
68
169
|
|
|
69
|
-
logMsg(msg,
|
|
70
|
-
|
|
170
|
+
logMsg(props = { msg: '', type: '' }) {
|
|
171
|
+
let t = this, fname = "QueueObj.logMsg"
|
|
172
|
+
try {
|
|
173
|
+
if (typeof props.msg == "undefined")
|
|
174
|
+
throw new Error(`no msg property in (${JSON.stringify(props)}) `)
|
|
175
|
+
if (typeof props.type == "undefined")
|
|
176
|
+
throw new Error(`no type property in (${JSON.stringify(props)}) `)
|
|
177
|
+
if (t.log_queue != null && typeof t.log_queue.logMsg != 'undefined') {
|
|
178
|
+
t.log_queue.logMsg(props)
|
|
179
|
+
} else {
|
|
180
|
+
throw new Error(`t.log_queue does not exist`)
|
|
181
|
+
}
|
|
182
|
+
} catch (e) {
|
|
183
|
+
e.message = `${fname} error: ${e.message})`
|
|
184
|
+
t.reject(e.message)
|
|
185
|
+
}
|
|
71
186
|
}
|
|
72
187
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2023-2-5l
|
|
4
|
+
* lib/appenders/all.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var base = require('./base.js')
|
|
8
|
+
|
|
9
|
+
exports = module.exports = class all extends base{
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props)
|
|
12
|
+
var t = this
|
|
13
|
+
t.aname = 'all'
|
|
14
|
+
t.pro_types = ['items']
|
|
15
|
+
return t
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2023-02-06
|
|
4
|
+
* lib/appenders/base.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var colors = require('colors')
|
|
8
|
+
|
|
9
|
+
class process_all_obj {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
let t = this
|
|
12
|
+
t.parent = props.parent
|
|
13
|
+
t.objs = t.parent.getParent().getObjs()
|
|
14
|
+
t.status = 'process'
|
|
15
|
+
t.process_objs_item = 0
|
|
16
|
+
t.process_props_item = 0
|
|
17
|
+
t.await_item = 0
|
|
18
|
+
t.any_errors = false
|
|
19
|
+
|
|
20
|
+
t.continueProcessing = t.continueProcessing.bind(t)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
process () {
|
|
24
|
+
let t = this
|
|
25
|
+
try {
|
|
26
|
+
if (t.process_objs_item >= t.objs.length) {
|
|
27
|
+
if (t.any_errors)
|
|
28
|
+
t.setStatus('finish with errors')
|
|
29
|
+
else
|
|
30
|
+
t.setStatus('finish')
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
let obj, pro, itm
|
|
35
|
+
try {
|
|
36
|
+
obj = t.parent.getParent().getItemToProcess(t.process_objs_item)
|
|
37
|
+
} catch (e) {
|
|
38
|
+
e.message = `base error: (${e.message})`
|
|
39
|
+
throw e
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
pro = (typeof obj == 'function') ? obj : obj.process;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
t.parent.getParent()(`pro error: (${e.message})`.red)
|
|
45
|
+
throw e
|
|
46
|
+
}
|
|
47
|
+
if (typeof t.parent.pro_props != 'undefined' &&
|
|
48
|
+
typeof t.parent.pro_props.property != 'undefined' &&
|
|
49
|
+
typeof t.parent.pro_props.items != 'undefined' &&
|
|
50
|
+
typeof obj._getProperty == 'function') {
|
|
51
|
+
let skip = true
|
|
52
|
+
for (let q = 0; q < t.parent.pro_props.items.length; q++) {
|
|
53
|
+
itm = t.parent.pro_props.items[q]
|
|
54
|
+
if (itm == obj._getProperty(obj)) {
|
|
55
|
+
skip = false
|
|
56
|
+
break
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (skip) {
|
|
60
|
+
t.continueProcessing()
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
t.setStatus('wait')
|
|
65
|
+
pro((obj_props) => {
|
|
66
|
+
try {
|
|
67
|
+
if (typeof obj_props != 'undefined' && typeof obj_props.error != 'undefined') {
|
|
68
|
+
t.any_errors = true
|
|
69
|
+
t.parent.getParent().logMsg(obj_props)
|
|
70
|
+
} else {
|
|
71
|
+
t.parent.getParent().logMsg(obj_props)
|
|
72
|
+
}
|
|
73
|
+
t.parent.results_array.push(obj_props)
|
|
74
|
+
t.continueProcessing()
|
|
75
|
+
} catch (e) {
|
|
76
|
+
t.parent.getParent().logMsg({msg: `pro obj error: (${e.message})`.error, type: "error"})
|
|
77
|
+
throw e
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
} catch (e) {
|
|
81
|
+
e.message = `error: ${e.message} `
|
|
82
|
+
throw e
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
e.message = `process_all_obj error: ${e.message} `
|
|
86
|
+
throw e
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
continueProcessing () {
|
|
91
|
+
let t = this
|
|
92
|
+
t.process_objs_item++
|
|
93
|
+
t.setStatus('process')
|
|
94
|
+
t.parent.process_all()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getStatus () {
|
|
98
|
+
return this.status
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
setStatus (v) {
|
|
102
|
+
this.status = v
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports = module.exports = class base {
|
|
107
|
+
constructor(props) {
|
|
108
|
+
let t = this
|
|
109
|
+
t.await_array = []
|
|
110
|
+
t.resolve_array = []
|
|
111
|
+
t.reject_array = []
|
|
112
|
+
t.results_array = []
|
|
113
|
+
t.getParent = props.getParent
|
|
114
|
+
t.dt_start = null
|
|
115
|
+
t.dt_end = null
|
|
116
|
+
t.process_all_obj = null
|
|
117
|
+
t.pro_props = []
|
|
118
|
+
|
|
119
|
+
t.process = t.process.bind(this)
|
|
120
|
+
t.process_all = t.process_all.bind(this)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// await(props) {
|
|
124
|
+
// let t = this
|
|
125
|
+
// t.await_array.push(props)
|
|
126
|
+
// return new Promise((resolve, reject) => {
|
|
127
|
+
// t.resolve_array.push(resolve)
|
|
128
|
+
// t.reject_array.push(reject)
|
|
129
|
+
// });
|
|
130
|
+
// }
|
|
131
|
+
|
|
132
|
+
process(props) {
|
|
133
|
+
let t = this
|
|
134
|
+
t.dt_start = new Date(); // start measuring time
|
|
135
|
+
|
|
136
|
+
t.pro_props = props
|
|
137
|
+
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
t.resolve_array.push(resolve)
|
|
140
|
+
t.reject_array.push(reject)
|
|
141
|
+
t.process_all()
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getStats() {
|
|
146
|
+
let t = this
|
|
147
|
+
t.dt_end = new Date();
|
|
148
|
+
let ret_str = '', st = t.dt_start, ed = t.dt_end, ml = t.dt_end - t.dt_start
|
|
149
|
+
// ret_str += JSON.stringify(t.results_array)
|
|
150
|
+
if (t.getParent().getStats()) {
|
|
151
|
+
ret_str += `start (${st}) end(${ed}) milliseconds(${ml})`
|
|
152
|
+
}
|
|
153
|
+
return ret_str
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
process_all () {
|
|
157
|
+
let t = this, _continue
|
|
158
|
+
if (t.process_all_obj == null) {
|
|
159
|
+
t.process_all_obj = new process_all_obj({ parent: t })
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
_continue = false
|
|
163
|
+
try {
|
|
164
|
+
switch (t.process_all_obj.getStatus()) {
|
|
165
|
+
case 'process':
|
|
166
|
+
t.process_all_obj.process()
|
|
167
|
+
_continue = true
|
|
168
|
+
break
|
|
169
|
+
case 'finish with errors':
|
|
170
|
+
t.reject_array[t.reject_array.length - 1](t.getStats())
|
|
171
|
+
break
|
|
172
|
+
case 'finish':
|
|
173
|
+
t.resolve_array[t.resolve_array.length - 1](t.getStats())
|
|
174
|
+
break
|
|
175
|
+
case 'wait':
|
|
176
|
+
return
|
|
177
|
+
default:
|
|
178
|
+
throw new Error(`status(${t.process_all_obj.getStatus()}) does not exist`)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (_continue)
|
|
182
|
+
t.process_all()
|
|
183
|
+
} catch (e) {
|
|
184
|
+
e.message = `process_all error: ${e.message} `
|
|
185
|
+
throw e
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2023-2-5
|
|
4
|
+
* lib/appenders/bottom_one.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var base = require('./base.js')
|
|
8
|
+
|
|
9
|
+
exports = module.exports = class bottom_one extends base{
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props)
|
|
12
|
+
var t = this
|
|
13
|
+
t.aname = 'bottom_one'
|
|
14
|
+
t.pro_types = ['items']
|
|
15
|
+
return t
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2023-2-5
|
|
4
|
+
* lib/appenders/func_all.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var base = require('./base.js')
|
|
8
|
+
|
|
9
|
+
exports = module.exports = class func_all extends base {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props)
|
|
12
|
+
var t = this
|
|
13
|
+
t.aname = 'func_all'
|
|
14
|
+
t.pro_types = ['items']
|
|
15
|
+
return t
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2023-01-16
|
|
4
|
+
* lib/appenders/name.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var base = require('./base.js')
|
|
8
|
+
|
|
9
|
+
exports = module.exports = class name extends base {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props)
|
|
12
|
+
var t = this
|
|
13
|
+
t.aname = 'name'
|
|
14
|
+
t.pro_types = ['name']
|
|
15
|
+
return t
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @author Jim Manton: jrman@risebroadband.net
|
|
3
|
+
* @since 2023-01-16
|
|
4
|
+
* lib/appenders/status.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var base = require('./base.js')
|
|
8
|
+
|
|
9
|
+
exports = module.exports = class status extends base {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props)
|
|
12
|
+
var t = this
|
|
13
|
+
t.aname = 'status'
|
|
14
|
+
t.pro_types = ['status']
|
|
15
|
+
return t
|
|
16
|
+
}
|
|
17
|
+
}
|