@@ -37,28 +37,53 @@ module.exports.parseStd = parseStd
3737 * Reports stds outputed by the in-execution command.
3838 *
3939 * @param {Object } socket Socket's io socket that requested the execution
40- * @param {String } topic Original message's topic
4140 * @param {Object } originalMessage Message that originally requested the execution
4241 * @param {String } stdout Command's stdout output
4342 * @param {String } stderr Command's stderr output
4443 */
45- const progress = ( socket , topic , originalMessage , stdout , stderr ) => {
44+ const progress = async ( socket , originalMessage , stdout , stderr , date ) => {
4645 console . log ( ' || STDOUT/ERR. Reporting...' . yellow )
4746
4847 const res = Object . assign ( originalMessage , {
4948 stdout : parseStd ( stdout ) ,
50- stderr : parseStd ( stderr )
49+ stderr : parseStd ( stderr ) ,
50+ date : date || null
5151 } )
5252
5353 // Make sure the agent doesn't make a report to the server, unless there's
5454 // an actual std output to be reported.
5555 if ( ! res . stdout && ! res . stderr ) { return }
5656
57- socket . emit ( ` ${ topic } . progress` , res )
57+ await socket . emit ( 'tf.notify. progress' , res )
5858}
5959
6060module . exports . progress = progress
6161
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+
6287/**
6388 * Reports the final result of an execution.
6489 *
@@ -67,15 +92,13 @@ module.exports.progress = progress
6792 * @param {Object } originalMessage Message that originally requested the execution
6893 * @param {Object } res Object containing both stds
6994 */
70- const result = ( socket , topic , originalMessage , res ) => {
95+ const result = ( socket , originalMessage , res ) => {
7196 console . log ( ' || Command executed. Reporting...' . yellow )
7297
73- const message = Object . assign ( originalMessage , {
98+ socket . emit ( 'tf.notify.finish' , Object . assign ( originalMessage , {
7499 stdout : parseStd ( res . stdout ) ,
75100 stderr : parseStd ( res . stderr )
76- } )
77-
78- socket . emit ( `${ topic } .res` , message )
101+ } ) )
79102}
80103
81104module . exports . result = result
@@ -87,10 +110,10 @@ module.exports.result = result
87110 * @param {Object } originalMessage Message that originally requested the execution
88111 * @param {Object } executionResult Catched exception
89112 */
90- const exception = ( socket , topic , originalMessage , ex ) => {
113+ const exception = ( socket , originalMessage , ex ) => {
91114 console . log ( ' || Command returned error' . red )
92115
93- socket . emit ( ` ${ topic } . exception` , Object . assign ( originalMessage , { ex} ) )
116+ socket . emit ( 'tf.notify. exception' , Object . assign ( originalMessage , { ex} ) )
94117}
95118
96119module . exports . exception = exception
0 commit comments