Skip to content

Commit 65a5e7a

Browse files
authored
Merge pull request #2494 from trycompai/fix/suppress-inactive-org-emails
[dev] [claudfuen] fix/suppress-inactive-org-emails
2 parents 46ea6ff + 16adc03 commit 65a5e7a

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,37 @@ 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+
// Only email orgs that are active: have access, completed onboarding,
18+
// and at least one member logged in within the last 90 days
1319
const organizations = await db.organization.findMany({
20+
where: {
21+
hasAccess: true,
22+
onboardingCompleted: true,
23+
members: {
24+
some: {
25+
deactivated: false,
26+
user: {
27+
sessions: {
28+
some: {
29+
updatedAt: { gte: inactivityCutoff },
30+
},
31+
},
32+
},
33+
},
34+
},
35+
},
1436
select: {
1537
id: true,
1638
name: true,
@@ -36,7 +58,7 @@ export const weeklyTaskReminder = schedules.task({
3658
},
3759
});
3860

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

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

0 commit comments

Comments
 (0)