Skip to content
Snippets Groups Projects
Commit 90f1ec87 authored by Yogmatee Roochun's avatar Yogmatee Roochun
Browse files

gitlab-1179

parent 6961cfe5
No related branches found
No related tags found
3 merge requests!380Pipeline changes,!379Build step added for the master branch,!378k8s release
......@@ -68,6 +68,7 @@ queue.drain(() => {
queue.error((err, task) => {
logger.error(`Error in task ${task}: ${err}`)
process.exit(1)
})
function close(ftp) {
......@@ -109,9 +110,12 @@ async function checkNewFtpPackage(ftp, ftpBulkUploader, rootPathLocal) {
if (!targzFiles.length) {
resolve(0) // No files to download to local FTP space
}
downloadFtpFiles(targzFiles, ftp, rootPathFTP, rootPathLocal).then(() =>
resolve(targzFiles.length),
)
downloadFtpFiles(targzFiles, ftp, rootPathFTP, rootPathLocal)
.then(() => resolve(targzFiles.length))
.catch(err => {
logger.error(err.message)
reject(err.message)
})
})
})
ftp.on('error', () =>
......@@ -125,27 +129,20 @@ async function checkNewFtpPackage(ftp, ftpBulkUploader, rootPathLocal) {
}
function downloadFtpFiles(targzFiles, ftp, rootPathFTP, rootPathLocal) {
let counter = 0
return Promise.all(
targzFiles.map(
(file, index, array) =>
file =>
new Promise((resolve, reject) => {
const remoteFilePath = `${rootPathFTP}/${file.name}`
ftp.get(remoteFilePath, (err, stream) => {
if (err) {
logger.error(remoteFilePath)
logger.error(err.message)
counter += 1
if (counter === array.length) {
reject(err.message)
}
reject(err.message)
} else if (!stream) {
logger.error(remoteFilePath)
logger.error(`No FTP get stream`)
counter += 1
if (counter === array.length) {
reject(err.message)
}
reject(err.message)
} else {
const path = `${rootPathLocal}/${file.name}`
const writeStream = stream.pipe(fs.createWriteStream(path))
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment