Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(HostReport): better logs #10681

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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
22 changes: 13 additions & 9 deletions reports/host-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { generateHostFeeAmountForTransactionLoader } from '../server/graphql/loa
import { getHostTransactionsCsvAsAdmin } from '../server/lib/csv';
import emailLib from '../server/lib/email';
import { getBackersStats, getHostedCollectives, sumTransactions } from '../server/lib/hostlib';
import logger from '../server/lib/logger';
import { stripHTML } from '../server/lib/sanitize-html';
import { reportErrorToSentry, reportMessageToSentry } from '../server/lib/sentry';
import { getPaidTaxTransactions, getTaxesSummary, getTransactions } from '../server/lib/transactions';
Expand Down Expand Up @@ -96,7 +97,9 @@ const sendEmail = (emailTemplate, recipients, data, attachments) => {
}
debug('email data stats', JSON.stringify(data.stats, null, 2));
const options = { attachments };
return emailLib.send(emailTemplate, recipients, data, options);
for (const recipient of recipients) {
return emailLib.send(emailTemplate, recipient, data, options);
}
};

async function HostReport(year, month, hostId) {
Expand Down Expand Up @@ -130,7 +133,7 @@ async function HostReport(year, month, hostId) {
const csvFilename = `${moment(d).format(dateFormat)}-transactions.csv`;
const csvFilenameV2 = `${moment(d).format(dateFormat)}-transactions-v2.csv`;
const pdfFilename = `${moment(d).format(dateFormat)}-expenses.pdf`;
console.log('startDate', startDate, 'endDate', endDate);
logger.info('startDate', startDate, 'endDate', endDate);

year = year || startDate.getFullYear();

Expand Down Expand Up @@ -226,10 +229,11 @@ async function HostReport(year, month, hostId) {
data.erratumMessage = process.env.ERRATUM_MESSAGE;
data.erratumNumber = process.env.ERRATUM_NUMBER;

logger.info('>>> Processing host', host.slug);

if (GENERATE_LEGACY_REPORT) {
data.legacyReport = true;
summary.totalHosts++;
console.log('>>> Processing host', host.slug);
const note =
'using fxrate of the day of the transaction as provided by the ECB. Your effective fxrate may vary.';
const expensesPerPage = 30; // number of expenses per page of the Table Of Content (for PDF export)
Expand Down Expand Up @@ -281,7 +285,7 @@ async function HostReport(year, month, hostId) {
collectivesById = keyBy(collectives, 'id');
data.stats.totalCollectives = collectives.filter(c => c.type === 'COLLECTIVE').length;
summary.totalCollectives += data.stats.totalCollectives;
console.log(`>>> processing ${data.stats.totalCollectives} collectives`);
logger.info(`>>> processing ${data.stats.totalCollectives} collectives`);
let transactions = await getTransactions(Object.keys(collectivesById), startDate, endDate, {
where: {
HostCollectiveId: host.id,
Expand Down Expand Up @@ -311,10 +315,10 @@ async function HostReport(year, month, hostId) {

const paidTaxTransactions = await getPaidTaxTransactions(host.id, startDate, endDate);
if (!transactions.length && !paidTaxTransactions.length) {
console.log(`No transaction found for ${host.slug}, skipping`);
logger.info(`No transaction found for ${host.slug}, skipping`);
return;
}
console.log(`>>> processing ${transactions.length + paidTaxTransactions.length} transactions`);
logger.info(`>>> processing ${transactions.length + paidTaxTransactions.length} transactions`);
await enrichTransactionsWithHostFee(transactions);
transactions = await Promise.all(transactions.map(processTransaction));

Expand Down Expand Up @@ -508,7 +512,7 @@ async function HostReport(year, month, hostId) {
const admins = await getHostAdminsEmails(host);
await sendEmail(emailTemplate, admins, data, attachments);
} catch (e) {
console.error(`Error in processing host ${host.slug}:`, e);
logger.error(`Error in processing host ${host.slug}:`, e);
reportErrorToSentry(e);
debug(e);
}
Expand All @@ -532,12 +536,12 @@ async function HostReport(year, month, hostId) {
type: sequelize.QueryTypes.SELECT,
replacements: { startDate: startDate, endDate: endDate },
});
console.log(`Preparing the ${reportName} for ${hosts.length} hosts`);
logger.info(`Preparing the ${reportName} for ${hosts.length} hosts`);

for (const host of hosts) {
await processHost(host);
}
console.log('>>> All done. Exiting.');
logger.info('>>> All done. Exiting.');
}

export default HostReport;
Loading