@@ -19,8 +19,6 @@ let rowCount = 0;
19
19
let ax ;
20
20
let putUrl ;
21
21
22
- const resolveList = [ ] ;
23
-
24
22
exports . init = async function init ( cfg ) {
25
23
const delimiter = cfg . writer . separator || ',' ;
26
24
const header = cfg . includeHeaders !== 'No' ;
@@ -41,7 +39,7 @@ exports.init = async function init(cfg) {
41
39
signedUrl = await client . resources . storage . createSignedUrl ( ) ;
42
40
// signedUrl = {
43
41
// put_url: 'https://examlple.mock/putUrl',
44
- // get_url: 'https://examlple.mock/putUrl ',
42
+ // get_url: 'https://examlple.mock/getUrl ',
45
43
// };
46
44
putUrl = signedUrl . put_url ;
47
45
console . log ( 'CSV file to be uploaded file to uri=%s' , putUrl ) ;
@@ -55,53 +53,45 @@ exports.process = async function ProcessAction(msg, cfg) {
55
53
56
54
if ( timeout ) {
57
55
clearTimeout ( timeout ) ;
58
- resolveList . forEach ( ( res ) => {
59
- res ( ) ;
60
- } ) ;
61
56
}
62
57
63
- const result = new Promise ( ( resolve ) => {
64
- resolveList . push ( resolve ) ;
58
+ timeout = setTimeout ( async ( ) => {
59
+ console . log ( 'Closing the stream due to inactivity' ) ;
65
60
66
- timeout = setTimeout ( async ( ) => {
67
- console . log ( 'Closing the stream due to inactivity' ) ;
68
-
69
- const finalRowCount = rowCount ;
70
- console . log ( 'The resulting CSV file contains %s rows' , finalRowCount ) ;
71
- ax . put ( putUrl , stringifier , {
72
- method : 'PUT' ,
73
- timeout : REQUEST_TIMEOUT ,
74
- retry : REQUEST_MAX_RETRY ,
75
- delay : REQUEST_RETRY_DELAY ,
76
- maxContentLength : REQUEST_MAX_CONTENT_LENGTH ,
77
- } ) ;
78
- stringifier . end ( ) ;
79
- const messageToEmit = messages . newMessageWithBody ( {
80
- rowCount : finalRowCount ,
81
- } ) ;
82
- const fileName = `${ messageToEmit . id } .csv` ;
83
- messageToEmit . attachments [ fileName ] = {
84
- 'content-type' : 'text/csv' ,
85
- url : signedUrl . get_url ,
86
- } ;
87
- signedUrl = null ;
88
- rowCount = 0 ;
89
- console . log ( 'Emitting message %j' , messageToEmit ) ;
90
- await self . emit ( 'data' , messageToEmit ) ;
91
- await exports . init ( cfg ) ;
92
- resolve ( ) ;
93
- } , TIMEOUT_BETWEEN_EVENTS ) ;
61
+ const finalRowCount = rowCount ;
62
+ console . log ( 'The resulting CSV file contains %s rows' , finalRowCount ) ;
63
+ ax . put ( putUrl , stringifier , {
64
+ method : 'PUT' ,
65
+ timeout : REQUEST_TIMEOUT ,
66
+ retry : REQUEST_MAX_RETRY ,
67
+ delay : REQUEST_RETRY_DELAY ,
68
+ maxContentLength : REQUEST_MAX_CONTENT_LENGTH ,
69
+ } ) ;
70
+ stringifier . end ( ) ;
71
+ const messageToEmit = messages . newMessageWithBody ( {
72
+ rowCount : finalRowCount ,
73
+ } ) ;
74
+ const fileName = `${ messageToEmit . id } .csv` ;
75
+ messageToEmit . attachments [ fileName ] = {
76
+ 'content-type' : 'text/csv' ,
77
+ url : signedUrl . get_url ,
78
+ } ;
79
+ signedUrl = null ;
80
+ rowCount = 0 ;
81
+ console . log ( 'Emitting message %j' , messageToEmit ) ;
82
+ await self . emit ( 'data' , messageToEmit ) ;
83
+ await exports . init ( cfg ) ;
84
+ } , TIMEOUT_BETWEEN_EVENTS ) ;
94
85
95
- let row = msg . body . writer ;
96
- console . log ( `Incoming data: ${ JSON . stringify ( row ) } ` ) ;
97
- if ( cfg . writer . columns ) {
98
- const columns = Object . keys ( _ . keyBy ( cfg . writer . columns , 'property' ) ) ;
99
- row = _ . pick ( row , columns ) ;
100
- }
101
- console . log ( `Writing Row: ${ JSON . stringify ( row ) } ` ) ;
102
- stringifier . write ( row ) ;
103
- rowCount += 1 ;
104
- } ) ;
86
+ let row = msg . body . writer ;
87
+ console . log ( `Incoming data: ${ JSON . stringify ( row ) } ` ) ;
88
+ if ( cfg . writer . columns ) {
89
+ const columns = Object . keys ( _ . keyBy ( cfg . writer . columns , 'property' ) ) ;
90
+ row = _ . pick ( row , columns ) ;
91
+ }
92
+ console . log ( `Writing Row: ${ JSON . stringify ( row ) } ` ) ;
93
+ stringifier . write ( row ) ;
94
+ rowCount += 1 ;
105
95
106
- await result ;
96
+ await self . emit ( 'end' ) ;
107
97
} ;
0 commit comments