@vbarbarosh/node-helpers 3.0.0 → 3.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.
package/package.json
CHANGED
package/src/fs_write.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
-
const util = require('util');
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
async function fs_write(file, data, options = {})
|
|
4
|
+
{
|
|
5
|
+
return fs.promises.writeFile(file, data, options);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
module.exports = fs_write;
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
const Promise = require('bluebird');
|
|
2
2
|
const child_process = require('child_process');
|
|
3
|
+
const fs_path_resolve = require('./fs_path_resolve');
|
|
3
4
|
const fs_tempdir = require('./fs_mkdirp');
|
|
5
|
+
const fs_write_json = require('./fs_write_json');
|
|
4
6
|
const random_int = require('./random_int');
|
|
5
7
|
const redis_zshift = require('./redis_zshift');
|
|
6
8
|
const stream_data_ln = require('./stream_data_ln');
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
11
|
+
* Constantly monitors redis queue for incoming messages. After an incoming message was hit,
|
|
12
|
+
* dumps it into `request.json` and executes `spawn_command`. The current directory will be set
|
|
13
|
+
* to a new directory with just `request.json` inside. Result (`null`) and user-friendly
|
|
14
|
+
* statuses will be `rpush`ed to the output queue.
|
|
15
|
+
*
|
|
10
16
|
* @param options
|
|
11
17
|
* @returns {Promise<void>}
|
|
12
18
|
*
|
|
@@ -102,7 +108,7 @@ async function redis_poll_zshift_spawn_rpush(options)
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
async function worker(log,
|
|
111
|
+
async function worker(log, request, options)
|
|
106
112
|
{
|
|
107
113
|
const {redis, redis_output_queue, spawn_command, version} = options;
|
|
108
114
|
const {
|
|
@@ -114,19 +120,18 @@ async function worker(log, message, options)
|
|
|
114
120
|
log_worker_user_friendly_status,
|
|
115
121
|
} = options;
|
|
116
122
|
|
|
117
|
-
log(`[${log_worker_begin}] ${
|
|
123
|
+
log(`[${log_worker_begin}] ${request.uid}`);
|
|
118
124
|
|
|
119
125
|
try {
|
|
120
|
-
const uid =
|
|
121
|
-
const env = {...process.env, COLUMNS: 80, PATH: `${__dirname}:${process.env.PATH}`};
|
|
122
|
-
Object.keys(message).forEach(key => env[`BN_${key.toUpperCase()}`] = message[key]);
|
|
126
|
+
const uid = request.uid;
|
|
123
127
|
// GOTCHA
|
|
124
|
-
// Promise won't update its status until at least one
|
|
125
|
-
// be taken from output queue. Pushing generic "Started
|
|
128
|
+
// Promise won't update its status until at least one request would
|
|
129
|
+
// be taken from the output queue. Pushing generic "Started..." request
|
|
126
130
|
// will tell the promise to refresh its status.
|
|
127
131
|
await redis.rpush_p(redis_output_queue, JSON.stringify({uid, version, type: 'user_friendly_status', value: 'Started...'}));
|
|
128
132
|
await fs_tempdir(async function (d) {
|
|
129
|
-
|
|
133
|
+
await fs_write_json(fs_path_resolve(d, 'request.json'), request);
|
|
134
|
+
const proc = child_process.spawn(spawn_command, [], {cwd: d, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});
|
|
130
135
|
let end_stdout = function () {};
|
|
131
136
|
let end_stderr = function () {};
|
|
132
137
|
let end_user_friendly_status = function () {};
|