Skip to content

Commit 220e49e

Browse files
committed
1 parent c37eab7 commit 220e49e

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

config/default.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ module.exports = {
306306
// frequency of checking expired interview
307307
CRON_INTERVIEW_EXPIRED: process.env.CRON_INTERVIEW_EXPIRED || '*/5 * * * *',
308308
// frequency of checking interview schedule status which need remind job candidate to select time
309-
CRON_INTERVIEW_SCHEDULE_REMINDER: process.env.CRON_INTERVIEW_SCHEDULE_REMINDER || '00 00 13 * * 0-6',
309+
CRON_INTERVIEW_SCHEDULE_REMINDER: process.env.CRON_INTERVIEW_SCHEDULE_REMINDER || '*/5 * * * *',
310310
// frequency of cron checking for post interview actions
311311
CRON_POST_INTERVIEW: process.env.CRON_POST_INTERVIEW || '00 00 13 * * 0-6',
312312
// frequency of cron checking for upcoming resource bookings
@@ -319,10 +319,8 @@ module.exports = {
319319
INTERVIEW_COMPLETED_MATCH_WINDOW: process.env.INTERVIEW_COMPLETED_MATCH_WINDOW || 'PT5M',
320320
// The interview completed past time for fetching interviews
321321
INTERVIEW_COMPLETED_PAST_TIME: process.env.INTERVIEW_COMPLETED_PAST_TIME || 'PT4H',
322-
// Reminder after days if Job Candidate hasn't selected time
323-
INTERVIEW_REMINDER_DAY_AFTER: process.env.INTERVIEW_REMINDER_DAY_AFTER || 'P1D',
324-
// Reminder frequency if Job Candidate hasn't selected time, unit: day
325-
INTERVIEW_REMINDER_FREQUENCY: parseInt(process.env.INTERVIEW_REMINDER_FREQUENCY) || 1,
322+
// The match window for fetching scheduling interviews
323+
INTERVIEW_REMINDER_MATCH_WINDOW: process.env.INTERVIEW_REMINDER_MATCH_WINDOW || 'PT5M',
326324
// How far in the feature we may allow scheduling interview, unit: day
327325
INTERVIEW_AVAILABLE_DAYS_IN_FEATURE: parseInt(process.env.INTERVIEW_AVAILABLE_DAYS_IN_FEATURE) || 15,
328326
// The time before resource booking expiry when we should start sending notifications

scripts/demo-email-notifications/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function resetNotificationRecords () {
6969

7070
const interviewForReminder = await Interview.findById('a23e1bf2-1084-4cfe-a0d8-d83bc6fec655')
7171
// update hostUserId to test user phash_manager
72-
await interviewForReminder.update({ createdAt: moment().subtract(moment.duration(config.INTERVIEW_REMINDER_DAY_AFTER)).toDate(), hostUserId: '57646ff9-1cd3-4d3c-88ba-eb09a395366c' })
72+
await interviewForReminder.update({ createdAt: moment().toDate(), hostUserId: '57646ff9-1cd3-4d3c-88ba-eb09a395366c' })
7373

7474
const interviewExpired = await Interview.findById('505db942-79fe-4b6f-974c-b359e1b61967')
7575
await interviewExpired.update({ expireTimestamp: moment().subtract(moment.duration(1, 'days')).toDate(), hostUserId: '57646ff9-1cd3-4d3c-88ba-eb09a395366c' })

src/services/NotificationsSchedulerService.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,20 @@ async function sendNotification (currentUser, data, webNotifications = []) {
591591

592592
// Send notifications to job candicate for time selection reminder
593593
async function sendInterviewScheduleReminderNotifications () {
594-
const INTERVIEW_REMINDER_DAY_AFTER = config.get('INTERVIEW_REMINDER_DAY_AFTER')
595-
const INTERVIEW_REMINDER_FREQUENCY = config.get('INTERVIEW_REMINDER_FREQUENCY')
596-
597594
localLogger.debug('[sendInterviewScheduleReminderNotifications]: Looking for due records...')
598-
const currentTime = moment.utc()
599-
const compareTime = currentTime.add(-INTERVIEW_REMINDER_DAY_AFTER).add(1, 'days').startOf('day')
595+
596+
const window = moment.duration(config.INTERVIEW_REMINDER_MATCH_WINDOW)
597+
const currentTime = moment.utc().startOf('minute')
598+
const rangeStart = currentTime.clone().subtract(window)
599+
const rangeEnd = currentTime.clone()
600600

601601
const timestampFilter = {
602602
[Op.and]: [
603603
{
604-
[Op.lte]: compareTime
604+
[Op.gte]: rangeStart
605+
},
606+
{
607+
[Op.lt]: rangeEnd
605608
}
606609
]
607610
}
@@ -630,27 +633,24 @@ async function sendInterviewScheduleReminderNotifications () {
630633

631634
let interviewCount = 0
632635
for (const interview of interviews) {
633-
const start = moment(interview.createdAt)
634-
if (currentTime.subtract(INTERVIEW_REMINDER_DAY_AFTER).diff(start, 'days') % INTERVIEW_REMINDER_FREQUENCY === 0) {
635-
// sendEmail
636-
const data = await getDataForInterview(interview)
637-
if (!data) { continue }
638-
639-
if (!_.isEmpty(data.guestEmail)) {
640-
// send guest emails
641-
sendNotification({}, {
642-
template,
643-
recipients: [{ email: data.guestEmail }],
644-
data: {
645-
...data,
646-
subject: `Reminder: ${data.duration} minutes tech interview with ${data.guestFullName} for ${data.jobTitle} is requested by the Customer`
647-
}
648-
})
649-
} else {
650-
localLogger.error(`Interview id: ${interview.id} guest emails not present`, 'sendInterviewScheduleReminderNotifications')
651-
}
652-
interviewCount++
636+
// sendEmail
637+
const data = await getDataForInterview(interview)
638+
if (!data) { continue }
639+
640+
if (!_.isEmpty(data.guestEmail)) {
641+
// send guest emails
642+
sendNotification({}, {
643+
template,
644+
recipients: [{ email: data.guestEmail }],
645+
data: {
646+
...data,
647+
subject: `Reminder: ${data.duration} minutes tech interview with ${data.guestFullName} for ${data.jobTitle} is requested by the Customer`
648+
}
649+
})
650+
} else {
651+
localLogger.error(`Interview id: ${interview.id} guest emails not present`, 'sendInterviewScheduleReminderNotifications')
653652
}
653+
interviewCount++
654654
}
655655

656656
localLogger.debug(`[sendInterviewScheduleReminderNotifications]: Sent notifications for ${interviewCount} interviews which need to schedule.`)

0 commit comments

Comments
 (0)