Created
August 12, 2019 19:25
-
-
Save dperussina/a83a2c5a3319275be059a02b2f7adbf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseFile(callback) { | |
U.logLn('parseFile - Number of files to process', FILES.length); | |
if (FILES.length == 0) { | |
callback(false); | |
return; | |
} | |
DATA = []; | |
function parse(file) { | |
var csvFilePath = '/home/dperussina/apps/customer-api-connections/src/dania/queue/' + file; | |
return function (cb) { | |
try { | |
CSV() | |
.fromFile(csvFilePath) | |
.on('json', (jsonObj) => { | |
DATA.push(jsonObj); | |
}) | |
.on('done', (error) => { | |
if (error) { | |
ERRORS.push({ | |
source: 'parseFile', | |
stack: error | |
}); | |
cb(true, 'CSV error' + error); | |
return; | |
} | |
cb(false); | |
}); | |
} catch (err) { | |
ERRORS.push({ | |
stack: err, | |
file: csvFilePath | |
}); | |
cb(true); | |
} | |
} | |
} | |
Q(FILES, parse, function (err, reply) { | |
callback(err); | |
}); | |
} | |
function main() { | |
ASYNC.series([getFile, parseFile, mapFields, exec, cleanUp], done); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseFile(callback) { | |
U.logLn('parseFile - Number of files to process', FILES.length); | |
if (FILES.length == 0) { | |
callback(false); | |
return; | |
} | |
DATA = []; | |
function parse(file) { | |
//var csvFilePath = '/home/dperussina/apps/customer-api-connections/src/dania/queue/' + file; | |
var csvFilePath = './<DirectoryOfChoice>/' + file; | |
return function (cb) { | |
try { | |
CSV() | |
.fromFile(csvFilePath) | |
.on('json', (jsonObj) => { | |
DATA.push(jsonObj); | |
}) | |
.on('done', (error) => { | |
if (error) { | |
ERRORS.push({ | |
source: 'parseFile', | |
stack: error | |
}); | |
cb(true, 'CSV error' + error); | |
return; | |
} | |
cb(false); | |
}); | |
} catch (err) { | |
ERRORS.push({ | |
stack: err, | |
file: csvFilePath | |
}); | |
cb(true); | |
} | |
} | |
} | |
Q(FILES, parse, function (err, reply) { | |
callback(err); | |
}); | |
} | |
function main() { | |
//ASYNC.series([getFile, parseFile, mapFields, exec, cleanUp], done); | |
ASYNC.series([parseFile, mapFields, exec, cleanUp], done); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment