Skip to content

Commit

Permalink
add START_PAGE feature to pre-fxa email script
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Nov 21, 2019
1 parent a9db5cf commit 6b13947
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/send-email-to-pre-fxa-subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const EmailUtils = require("../email-utils");
const { LocaleUtils } = require ("../locale-utils");

const PAGE_SIZE = process.env.PAGE_SIZE;
const START_PAGE = process.env.START_PAGE;

if (!START_PAGE) {
console.error("You must provide a START_PAGE environment variable.");
process.exit();
}


(async (req) => {
Expand All @@ -19,13 +25,14 @@ const PAGE_SIZE = process.env.PAGE_SIZE;
const notifiedSubscribers = [];
const utmID = "pre-fxa";

const subscribersResult = await DB.getPreFxaSubscribersPage({ perPage: PAGE_SIZE, currentPage: 1 });
const subscribersResult = await DB.getPreFxaSubscribersPage({ perPage: PAGE_SIZE, currentPage: START_PAGE, isLengthAware: true });
const numPagesToProcess = subscribersResult.pagination.lastPage - START_PAGE;
console.log(`Found ${subscribersResult.pagination.total} subscriber records with empty fxa_uid.`);
console.log(`Will process ${subscribersResult.pagination.lastPage} pages of size ${PAGE_SIZE}.`);
console.log(`Will process ${numPagesToProcess} pages of size ${PAGE_SIZE}, starting with page ${START_PAGE} and ending with page ${subscribersResult.pagination.lastPage}.`);
const lastPage = subscribersResult.pagination.lastPage;


for (let currentPage = 1; currentPage <= lastPage; currentPage++) {
for (let currentPage = START_PAGE; currentPage <= lastPage; currentPage++) {
console.log(`Processing page ${currentPage} of ${lastPage}.`);
const subscribersPageResult = await DB.getPreFxaSubscribersPage({ perPage: PAGE_SIZE, currentPage });
for (const subscriber of subscribersPageResult.data) {
Expand Down

0 comments on commit 6b13947

Please sign in to comment.