Skip to content

Commit 91983b6

Browse files
committed
move nodesfc to agent service
1 parent 89e4745 commit 91983b6

File tree

5 files changed

+5070
-127
lines changed

5 files changed

+5070
-127
lines changed

agent.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,11 @@ module.exports.exec = (program) => {
7070
q.push(services.agent.execute(socket, 'tf.agent.execute', req))
7171
})
7272

73-
// Execute code
74-
socket.on('tf.agent.code', function () {
73+
socket.on('tf.agent.code_nodesfc', function(req) {
7574
if (!agent.authenticated) return
76-
q.push(services.agent.code(socket, 'tf.agent.code', req))
75+
q.push(services.agent.codeNodeSfc(socket, 'tf.agent.code_nodesfc', req))
7776
})
78-
77+
7978
// Authorize agent
8079
socket.on('tf.authz', function (auth) {
8180
agent = Object.assign({authenticated: true}, agent, auth)

helpers/report.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,49 @@ module.exports.parseStd = parseStd
4141
* @param {String} stdout Command's stdout output
4242
* @param {String} stderr Command's stderr output
4343
*/
44-
const progress = (socket, originalMessage, stdout, stderr) => {
44+
const progress = async (socket, originalMessage, stdout, stderr, date) => {
4545
console.log(' || STDOUT/ERR. Reporting...'.yellow)
4646

4747
const res = Object.assign(originalMessage, {
4848
stdout: parseStd(stdout),
49-
stderr: parseStd(stderr)
49+
stderr: parseStd(stderr),
50+
date: date || null
5051
})
5152

5253
// Make sure the agent doesn't make a report to the server, unless there's
5354
// an actual std output to be reported.
5455
if (!res.stdout && !res.stderr) { return }
5556

56-
socket.emit('tf.notify.progress', res)
57+
await socket.emit('tf.notify.progress', res)
5758
}
5859

5960
module.exports.progress = progress
6061

62+
/**
63+
* Reports the final result of an execution, with
64+
* all stds as an array
65+
*
66+
* @param {Object} socket Socket's io socket that requested the execution
67+
* @param {Object} originalMessage Message that originally requested the execution
68+
* @param {object} result Command's stds and exit code output:
69+
*
70+
* {
71+
* stdLines: [{
72+
* output: string,
73+
* err: boolean,
74+
* date: date
75+
* }],
76+
* code: number
77+
* }
78+
*/
79+
const bulkResult = async (socket, originalMessage, result) => {
80+
console.log(' || BULK STDOUT/ERR. Reporting...'.yellow)
81+
const res = Object.assign(originalMessage, result)
82+
await socket.emit('tf.notify.finishBulk', res)
83+
}
84+
85+
module.exports.bulkResult = bulkResult
86+
6187
/**
6288
* Reports the final result of an execution.
6389
*

0 commit comments

Comments
 (0)