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

MNTOR-3919: cronjob WIP for churn emails #5495

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c91b346
feat: add cronjob for churn discount
mansaj Jan 9, 2025
f4027ec
feat: add package
mansaj Jan 13, 2025
b85fcf0
Merge branch 'main' into MNTOR-3919
mansaj Jan 13, 2025
1533e8f
feat: discount email cron job
mansaj Jan 13, 2025
b6d5ec9
Merge branch 'main' into MNTOR-3919
mansaj Jan 13, 2025
e6084b3
feat: more logic for churn email
mansaj Jan 14, 2025
a1a3719
feat: filter the results to the batch we want to send now
mansaj Jan 14, 2025
78f0831
feat: no need for batch
mansaj Jan 14, 2025
3b792a5
feat: fix logs
mansaj Jan 14, 2025
3e5199c
fix: hide unused imports
mansaj Jan 14, 2025
c4025e2
fix: continue when sent date is present
mansaj Jan 14, 2025
e565c89
fix: why is there console log
mansaj Jan 14, 2025
8d30d8d
feat: subscriber churns upsert and table
mansaj Jan 16, 2025
dcb50d7
Merge branch 'MNTOR-3919' into MNTOR-3918
mansaj Jan 16, 2025
2533527
feat: get subscribers for table
mansaj Jan 17, 2025
7aeb6a2
feat: admin panel for churn management
mansaj Jan 17, 2025
3bac917
Update src/app/(proper_react)/(redesign)/(authenticated)/admin/churn-…
mansaj Jan 21, 2025
e828419
fix: lint
mansaj Jan 21, 2025
9c52c2c
Update src/db/tables/subscriber_churns.ts
mansaj Jan 21, 2025
0306bf7
Merge branch 'MNTOR-3918' of https://github.com/mozilla/blurts-server…
mansaj Jan 21, 2025
1540605
fix: define in knex table type
mansaj Jan 21, 2025
88afc4c
fix: using bitquery
mansaj Jan 22, 2025
3cb5ce2
fix: rename
mansaj Jan 22, 2025
2bda261
Update package.json
mansaj Jan 22, 2025
3a513a2
Update .env
mansaj Jan 22, 2025
f45f3aa
Update package.json
mansaj Jan 22, 2025
899a9f5
fix: del
mansaj Jan 22, 2025
729f52b
fix: add a check here that the headers and number of columns match wh…
mansaj Jan 22, 2025
b484d3a
feat: add a del all function for the churns table
mansaj Jan 22, 2025
39b2ed3
Merge pull request #5512 from mozilla/MNTOR-3918
mansaj Jan 22, 2025
4f928e7
Merge branch 'MNTOR-3919' of https://github.com/mozilla/blurts-server…
mansaj Jan 22, 2025
f0450e6
fix: big query keyfile path
mansaj Jan 22, 2025
35e281c
Merge branch 'MNTOR-3918' into MNTOR-3919
mansaj Jan 22, 2025
9409d0d
fix: pull churn data from db
mansaj Jan 22, 2025
7944fa6
fix: get churns to email func
mansaj Jan 22, 2025
e8118ec
Merge branch 'main' into MNTOR-3919
mansaj Jan 23, 2025
58d94fd
Merge branch 'main' into MNTOR-3919
mansaj Jan 27, 2025
b940f5e
fix: get rid of bigquery
mansaj Jan 27, 2025
5f3034e
fix: better raw queries
mansaj Jan 27, 2025
e226873
feat: cronjob churn
mansaj Jan 27, 2025
af2da88
fix: del env vars
mansaj Jan 27, 2025
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
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ AWS_SECRET_ACCESS_KEY=
AWS_REGION=
S3_BUCKET=

# GCP bucket
GCP_STORAGE_SA_PATH=
GCP_STORAGE_PROJECT_ID=
GCP_BUCKET=
mansaj marked this conversation as resolved.
Show resolved Hide resolved

# Firefox Accounts OAuth
FXA_SETTINGS_URL=https://accounts.stage.mozaws.net/settings

Expand Down
148 changes: 137 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@
"@fluent/bundle": "^0.18.0",
"@fluent/langneg": "^0.7.0",
"@fluent/react": "^0.15.2",
"@google-cloud/bigquery": "^7.9.1",
"@google-cloud/logging-winston": "^6.0.0",
"@google-cloud/pubsub": "^4.9.0",
"@google-cloud/storage": "^7.15.0",
mansaj marked this conversation as resolved.
Show resolved Hide resolved
"@grpc/grpc-js": "1.12.2",
"@leeoniya/ufuzzy": "^1.0.17",
"@mozilla/glean": "^5.0.3",
Expand All @@ -90,6 +92,7 @@
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"canvas-confetti": "^1.9.3",
"csv-parser": "^3.1.0",
mansaj marked this conversation as resolved.
Show resolved Hide resolved
"dotenv-flow": "^4.1.0",
"eslint-config-next": "^14.2.15",
"ioredis": "^5.4.2",
Expand Down
27 changes: 27 additions & 0 deletions src/db/migrations/20250115032133_subscriber_churns.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

export async function up(knex) {
await knex.schema
.createTable('subscriber_churns', function(table) {
table.increments('id').primary();
table.string('userid').unique();
table.string('customer').unique();
table.string('plan_id');
table.string('product_id');
table.string('intervl');
table.string('nickname');
table.timestamp('created');
table.timestamp('current_period_end');
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex) {
return knex.schema
.dropTableIfExists("subscriber_churns")
}
35 changes: 35 additions & 0 deletions src/db/tables/subscriber_churns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import createDbConnection from "../connect";
import { logger } from "../../app/functions/server/logging";
import { SubscriberChurnRow } from "knex/types/tables";

const knex = createDbConnection();

async function upsertSubscriberChurns(
churningSubscribers: SubscriberChurnRow[],
): Promise<SubscriberChurnRow[]> {
logger.info("upsert_subscriber_churns", {
count: churningSubscribers.length,
});

try {
const res = await knex("onerep_subscriber_churns")
.insert(churningSubscribers)
.onConflict("userid")
.merge(["intervl", "current_period_end"])
.returning("*");

logger.info("upsert_subscriber_churns_success", { count: res.length });
return res as SubscriberChurnRow[];
} catch (e) {
logger.error("upsert_subscriber_churns_error", {
error: JSON.stringify(e),
});
throw e;
}
}

export { upsertSubscriberChurns };
10 changes: 10 additions & 0 deletions src/knex-tables.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ declare module "knex/types/tables" {
updated_at: Date;
}

interface SubscriberChurnRow {
userid: string;
customer: string;
nickname: string;
intervl: string;
plan_id: string;
product_id: string;
current_period_end: string;
}

interface OnerepScanResultDataBrokerRow extends OnerepScanResultRow {
scan_result_status: RemovalStatus;
broker_status: DataBrokerRemovalStatus;
Expand Down
Loading
Loading