Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ function saveVehicles() {

return writeHelper.writeToS3(s3Bucket, agencyInfo.id, currentDateTime, vehicles);
})
.catch((err) => {
console.log(err);
});
});

Promise.all(promises);
// Do not reject all promises when one of them is rejected, but do output why one (or more) was rejected.
Promise.allSettled(promises)
.then((results) => results.forEach((result) => {
if(result.status == "rejected") {
console.log("received a rejected promise with reason:", result.reason)
}
}));
}

function storeLocal() {
Expand Down
17 changes: 9 additions & 8 deletions src/writeHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const AWS = require('aws-sdk');
const fs = require('fs');
const s3 = new AWS.S3();
const { writeFile } = require('fs/promises');

var zlib = require('zlib');

const s3 = new AWS.S3();


function compressData(data) {
return new Promise((resolve, _) => {
Expand All @@ -17,12 +19,11 @@ function writeLocal(agency, currentDateTime, data) {
const version = "v1";
const fileName = `/tmp/${agency}_${version}_${currentTimestamp}.json`

fs.writeFile(fileName, JSON.stringify(data), err => {
if (err) {
console.error(err);
}
console.log("wrote", fileName)
});
return writeFile(fileName, JSON.stringify(data))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Does this work without importing writeFile?

import { writeFile } from 'fs/promises';`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. Just realized this project is using CommonJS.

const { writeFile } = require('fs/promises);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep the second way seems to work as expected, thanks for the suggestion 👍

.then((data) => {
console.log("wrote", fileName);
return data;
});
}

function writeToS3(s3Bucket, agency, currentDateTime, data) {
Expand Down