@@ -591,17 +591,20 @@ async function sendNotification (currentUser, data, webNotifications = []) {
591
591
592
592
// Send notifications to job candicate for time selection reminder
593
593
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
-
597
594
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 ( )
600
600
601
601
const timestampFilter = {
602
602
[ Op . and ] : [
603
603
{
604
- [ Op . lte ] : compareTime
604
+ [ Op . gte ] : rangeStart
605
+ } ,
606
+ {
607
+ [ Op . lt ] : rangeEnd
605
608
}
606
609
]
607
610
}
@@ -630,27 +633,24 @@ async function sendInterviewScheduleReminderNotifications () {
630
633
631
634
let interviewCount = 0
632
635
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' )
653
652
}
653
+ interviewCount ++
654
654
}
655
655
656
656
localLogger . debug ( `[sendInterviewScheduleReminderNotifications]: Sent notifications for ${ interviewCount } interviews which need to schedule.` )
0 commit comments