Skip to content

Commit

Permalink
Merge pull request #286 from Sunbird-cQube/dev
Browse files Browse the repository at this point in the history
Merging changes from dev to staging
  • Loading branch information
pandutibil authored Oct 12, 2023
2 parents 94ec318 + a95f221 commit f6731e2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/ingestion/services/generic-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,22 @@ export class GenericFunction {
} while (true);
// get the lock on the file
this.currentlyLockedFiles[fileName] = true;

const fileExists = fs.existsSync(fileName);
const stream = fs.createWriteStream(fileName,{flags:'a'});
await csv.write(inputArray, { headers: true})
.pipe(stream)
.on('finish', () => {
if(!fileExists){
await csv.write(inputArray, { headers: true }).pipe(stream);
}else{
await csv.write(inputArray).pipe(stream);
}
// await csv.write(inputArray, { headers: true})
// .pipe(stream)
stream.on('finish', () => {
console.log('CSV file has been written successfully');
// delete the lock after writing
delete this.currentlyLockedFiles[fileName];
resolve('done')
})
.on('error', (err) => {
stream.on('error', (err) => {
console.error('Error writing CSV file:', err);
reject(err)
});
Expand Down

0 comments on commit f6731e2

Please sign in to comment.