Skip to content

Commit df38287

Browse files
claudfuenclaude
andcommitted
fix: suppress weekly digest emails for inactive orgs
Skip organizations where no member has logged in within 90 days. Prevents sending emails to dead/abandoned addresses that may have become spam traps, which contributes to domain reputation damage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 46ea6ff commit df38287

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

apps/app/src/trigger/tasks/task/weekly-task-reminder.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,33 @@ import { db } from '@db/server';
22
import { logger, schedules } from '@trigger.dev/sdk';
33
import { sendWeeklyTaskDigestEmailTask } from '../email/weekly-task-digest-email';
44

5+
const ORG_INACTIVITY_DAYS = 90;
6+
57
export const weeklyTaskReminder = schedules.task({
68
id: 'weekly-task-reminder',
79
cron: '0 9 * * 1', // Every Monday at 9:00 AM UTC
810
maxDuration: 1000 * 60 * 10, // 10 minutes
911
run: async () => {
1012
logger.info('Starting weekly task reminder job');
1113

12-
// Get all organizations
14+
const inactivityCutoff = new Date();
15+
inactivityCutoff.setDate(inactivityCutoff.getDate() - ORG_INACTIVITY_DAYS);
16+
17+
// Get all organizations that have at least one session updated in the last 90 days
1318
const organizations = await db.organization.findMany({
19+
where: {
20+
members: {
21+
some: {
22+
user: {
23+
sessions: {
24+
some: {
25+
updatedAt: { gte: inactivityCutoff },
26+
},
27+
},
28+
},
29+
},
30+
},
31+
},
1432
select: {
1533
id: true,
1634
name: true,
@@ -36,7 +54,7 @@ export const weeklyTaskReminder = schedules.task({
3654
},
3755
});
3856

39-
logger.info(`Found ${organizations.length} organizations to process`);
57+
logger.info(`Found ${organizations.length} active organizations to process (skipped orgs with no sessions in ${ORG_INACTIVITY_DAYS} days)`);
4058

4159
// Build email payloads for all members with TODO tasks
4260
const emailPayloads = [];

0 commit comments

Comments
 (0)