Skip to content
Merged
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions jobs/periodic/process-expired-coc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import { prisma } from '../../../common/prisma';
import { getLogger } from '../../../common/logger/logger';
import moment from 'moment';
import { scheduleCoCReminders } from '../../../common/student/screening';
import { predictedHookActionDate } from '../../../common/notification';
import { userForStudent } from '../../../common/user';

const logger = getLogger();

export default async function execute() {
const thirtyThreeMonthsAgo = moment().subtract(33, 'months').toDate();
const twoMonthsAgo = moment().subtract(2, 'months').toDate();
const activeStudentsWithoutCoC = await prisma.student.findMany({
where: {
active: true,
lastLogin: {
gt: twoMonthsAgo,
},
certificate_of_conduct: { is: null },
OR: [{ screening: { status: 'success' } }, { instructor_screening: { status: 'success' } }],
},
});
const studentsWithStaleCoC = await prisma.student.findMany({
where: {
active: true,
Expand Down Expand Up @@ -37,4 +49,17 @@ export default async function execute() {
await scheduleCoCReminders(student, /** ignoreAccCreationDate: */ false, /** isRenewal: */ true);
}
logger.info(`Scheduled CoC reminders for ${studentsWithStaleCoC.length} students.`);

let scheduledForMissingCoC = 0;
for (const student of activeStudentsWithoutCoC) {
// Rescheduling cancels the pending deactivation, so students already in the countdown must be skipped
const deactivationAlreadyScheduled = await predictedHookActionDate('coc_reminder', 'deactivate-student', userForStudent(student));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I think this correctly skips our test users then?)

@JeangelLF JeangelLF Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think so. One of them for example is already in the countdown and the deactivation date is set to 2050 and the other one is not screened yet

if (deactivationAlreadyScheduled) {
continue;
}
// We also treat these cases as renewals
await scheduleCoCReminders(student, /** ignoreAccCreationDate: */ false, /** isRenewal: */ true);
scheduledForMissingCoC++;
}
logger.info(`Scheduled CoC reminders for ${scheduledForMissingCoC} students without a CoC.`);
}
Loading