Skip to content

Commit a5e681f

Browse files
committed
feat(inactive-accts): use one task queue per email type
Because: - we want to simplify email cloud task scheduling and rate limiting by using one Google cloud task queue per email notification type This commit: - uses one cloud task queue per email type - renames numerous things to make it clear that these queues and tasks are for inactive deletion emails only - updates route handler and InactiveAccountManager
1 parent 976588a commit a5e681f

16 files changed

Lines changed: 705 additions & 627 deletions

File tree

_scripts/cloud-tasks-emulator.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
docker run --rm \
44
--name cloud-tasks-emulator \
55
-p 8123:8123 \
6-
ghcr.io/aertje/cloud-tasks-emulator:latest -host "0.0.0.0" -port "8123" -queue "projects/test/locations/test/queues/delete-accounts-queue" -queue "projects/test/locations/test/queues/notification-emails-queue"
6+
ghcr.io/aertje/cloud-tasks-emulator:latest -host "0.0.0.0" -port "8123" -queue "projects/test/locations/test/queues/delete-accounts-queue" -queue "projects/test/locations/test/queues/inactive-first-email" -queue "projects/test/locations/test/queues/inactive-second-email" -queue "projects/test/locations/test/queues/inactive-third-email"

libs/shared/cloud-tasks/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ export * from './lib/cloud-tasks.factories';
33
export * from './lib/cloud-tasks.types';
44

55
export * from './lib/delete-account-tasks';
6-
export * from './lib/send-email-tasks';
6+
export * from './lib/inactive-account-email-tasks';
77
export * from './lib/account-tasks.factories';
88
export * from './lib/account-tasks.types';

libs/shared/cloud-tasks/src/lib/account-tasks.factories.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import { StatsD } from 'hot-shots';
66
import {
77
DeleteAccountCloudTaskConfig,
8-
SendEmailCloudTaskConfig,
8+
InactiveAccountEmailCloudTaskConfig,
99
} from './account-tasks.types';
1010
import { CloudTaskClientFactory } from './cloud-tasks.factories';
1111
import { DeleteAccountTasks } from './delete-account-tasks';
12-
import { SendEmailTasks } from './send-email-tasks';
12+
import { InactiveAccountEmailTasks } from './inactive-account-email-tasks';
1313

1414
/** Produces a DeleteAccountCloudTask instance */
1515
export function DeleteAccountTasksFactory(
@@ -20,10 +20,10 @@ export function DeleteAccountTasksFactory(
2020
return new DeleteAccountTasks(config, client, statsd);
2121
}
2222

23-
export function SendEmailTasksFactory(
24-
config: SendEmailCloudTaskConfig,
23+
export function InactiveAccountEmailTasksFactory(
24+
config: InactiveAccountEmailCloudTaskConfig,
2525
statsd: Pick<StatsD, 'increment'>
2626
) {
2727
const client = CloudTaskClientFactory(config);
28-
return new SendEmailTasks(config, client, statsd);
28+
return new InactiveAccountEmailTasks(config, client, statsd);
2929
}

libs/shared/cloud-tasks/src/lib/account-tasks.types.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { CloudTasksConfig } from './cloud-tasks.types';
6-
import { CloudTaskEmailType } from './send-email-tasks';
6+
import { CloudTaskEmailType } from './inactive-account-email-tasks';
77

88
export type FxACloudTaskHeaders = {
99
'fxa-cloud-task-delivery-time'?: string;
@@ -24,6 +24,7 @@ export enum ReasonForDeletion {
2424
UserRequested = 'fxa_user_requested_account_delete',
2525
Unverified = 'fxa_unverified_account_delete',
2626
Cleanup = 'fxa_cleanup_account_delete',
27+
InactiveAccount = 'fxa_inactive_account_delete',
2728
}
2829

2930
/** Task payload requesting an account deletion */
@@ -36,11 +37,15 @@ export type DeleteAccountTask = {
3637
reason: ReasonForDeletion;
3738
};
3839

39-
export type SendEmailCloudTaskConfig = CloudTasksConfig & {
40+
export type InactiveAccountEmailCloudTaskConfig = CloudTasksConfig & {
4041
cloudTasks: {
41-
sendEmails: {
42+
inactiveAccountEmails: {
4243
taskUrl: string;
43-
queueName: string;
44+
firstEmailQueueName: string;
45+
secondEmailQueueName: string;
46+
thirdEmailQueueName: string;
47+
firstToSecondEmailIntervalMs: number;
48+
secondToThirdEmailIntervalMs: number;
4449
};
4550
};
4651
};
@@ -49,3 +54,7 @@ export type SendEmailTaskPayload = {
4954
uid: string;
5055
emailType: CloudTaskEmailType;
5156
};
57+
export type InactiveAccountEmailTaskPayloadParam = Omit<
58+
SendEmailTaskPayload,
59+
'emailType'
60+
>;

libs/shared/cloud-tasks/src/lib/cloud-tasks.factories.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,43 @@ export function CloudTasksConvictConfigFactory() {
6767
format: String,
6868
},
6969
},
70-
sendEmails: {
70+
inactiveAccountEmails: {
7171
taskUrl: {
7272
default: '',
7373
doc: 'URL that sends the email',
7474
env: 'AUTH_CLOUDTASKS_NOTIFICATION_EMAILS_TASK_URL',
7575
format: String,
7676
},
77-
queueName: {
78-
default: 'notification-emails-queue',
79-
doc: 'The name of the queue. It should match the x-cloudtasks-queuename header value sent to the target.',
80-
env: `AUTH_CLOUDTASKS_NOTIFICATION_EMAILS_QUEUENAME`,
77+
firstEmailQueueName: {
78+
default: 'inactives-first-email',
79+
doc: 'The name of the queue for the first email. It should match the x-cloudtasks-queuename header value sent to the target.',
80+
env: 'AUTH_CLOUDTASKS_INACTIVE_ACCT_FIRST_EMAIL_QUEUENAME',
81+
format: String,
82+
},
83+
secondEmailQueueName: {
84+
default: 'inactives-second-email',
85+
doc: 'The name of the queue for the second email. It should match the x-cloudtasks-queuename header value sent to the target.',
86+
env: 'AUTH_CLOUDTASKS_INACTIVE_ACCT_SECOND_EMAIL_QUEUENAME',
8187
format: String,
8288
},
89+
thirdEmailQueueName: {
90+
default: 'inactives-third-email',
91+
doc: 'The name of the queue for the third email. It should match the x-cloudtasks-queuename header value sent to the target.',
92+
env: 'AUTH_CLOUDTASKS_INACTIVE_ACCT_THIRD_EMAIL_QUEUENAME',
93+
format: String,
94+
},
95+
firstToSecondEmailIntervalMs: {
96+
default: 53 * 24 * 60 * 60 * 1000,
97+
doc: 'The interval between the first and second email in milliseconds.',
98+
env: 'AUTH_CLOUDTASKS_INACTIVE_ACCT_FIRST_TO_SECOND_EMAIL_INTERVAL',
99+
format: Number,
100+
},
101+
secondToThirdEmailIntervalMs: {
102+
default: 6 * 24 * 60 * 60 * 1000,
103+
doc: 'The interval between the second and third email in milliseconds.',
104+
env: 'AUTH_CLOUDTASKS_INACTIVE_ACCT_SECOND_TO_THIRD_EMAIL_INTERVAL',
105+
format: Number,
106+
},
83107
},
84108
};
85109
}

0 commit comments

Comments
 (0)