Skip to content

Commit

Permalink
fix: rework to utilize env var if possible/correct
Browse files Browse the repository at this point in the history
  • Loading branch information
mansaj committed Dec 19, 2024
1 parent b5982f2 commit 84b77b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@ export const CONST_SETTINGS_TAB_SLUGS = [
"notifications",
"manage-account",
] as const;

export const MONTHLY_ACTIVITY_FREE_EMAIL_BATCH_SIZE = 5;
12 changes: 10 additions & 2 deletions src/scripts/cronjobs/monthlyActivityFree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ import createDbConnection from "../../db/connect";
import { logger } from "../../app/functions/server/logging";
import { getMonthlyActivityFreeUnsubscribeLink } from "../../app/functions/cronjobs/unsubscribeLinks";
import { hasPremium } from "../../app/functions/universal/user";
import { MONTHLY_ACTIVITY_FREE_EMAIL_BATCH_SIZE } from "../../constants";

await run();
await createDbConnection().destroy();

async function run() {
const batchSize = MONTHLY_ACTIVITY_FREE_EMAIL_BATCH_SIZE;
let batchSize = Number.parseInt(
process.env.MONTHLY_ACTIVITY_FREE_EMAIL_BATCH_SIZE ?? "10",
10,
);
if (Number.isNaN(batchSize)) {
batchSize = 10;
logger.warn(
`Could not send monthly activity emails, because the env var MONTHLY_ACTIVITY_FREE_EMAIL_BATCH_SIZE has a non-numeric value: [${process.env.MONTHLY_ACTIVITY_FREE_EMAIL_BATCH_SIZE}].`,
);
}

logger.info(`Getting free subscribers with batch size: ${batchSize}`);
const subscribersToEmail = (await getFreeSubscribersWaitingForMonthlyEmail())
Expand Down

0 comments on commit 84b77b5

Please sign in to comment.