Skip to content

Commit

Permalink
fix: always compress bounce report csv with gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Sep 27, 2023
1 parent bc419d7 commit 86b0a4e
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions jobs/bounce-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { parentPort } = require('node:worker_threads');
require('#config/mongoose');

const Graceful = require('@ladjs/graceful');
const bytes = require('bytes');
const dayjs = require('dayjs-with-plugins');
const humanize = require('humanize-string');
const mongoose = require('mongoose');
Expand All @@ -23,8 +22,6 @@ const emailHelper = require('#helpers/email');
const logger = require('#helpers/logger');
const setupMongoose = require('#helpers/setup-mongoose');

const BYTES_8MB = bytes('8MB');

const graceful = new Graceful({
mongooses: [mongoose],
logger
Expand Down Expand Up @@ -231,20 +228,6 @@ function makeDelimitedString(arr) {
.join('</li><li>')}</li></ul>`
].join('\n');

let filename = `email-deliverability-logs-${dayjs(now).format(
'YYYY-MM-DD-h-mm-A-z'
)}.csv`.toLowerCase();

const buffer = Buffer.from(csv.join('\n', 'utf8'));

let content;
if (Buffer.byteLength(buffer) > BYTES_8MB) {
content = zlib.gzipSync(buffer, { level: 9 });
filename += '.gz';
} else {
content = buffer;
}

// email the spreadsheet to admins
await emailHelper({
template: 'alert',
Expand All @@ -255,8 +238,12 @@ function makeDelimitedString(arr) {
).format('M/D/YY h:mm A z')} (${set.size} trusted hosts blocked)`,
attachments: [
{
filename,
content
filename: `email-deliverability-logs-${dayjs(now).format(
'YYYY-MM-DD-h-mm-A-z'
)}.csv.gz`.toLowerCase(),
content: zlib.gzipSync(Buffer.from(csv.join('\n', 'utf8')), {
level: 9
})
}
]
},
Expand Down

0 comments on commit 86b0a4e

Please sign in to comment.