     "metadata.timeRangeName": @timeRange.name
     "metadata.updated": candidate.jobProfile.updated
   MailSent.find(findParameters).lean().exec (err, sentMail) ->
-    if err? then return errors.serverError("Error fetching sent mail in email task")
-    sentEmailFilterCallback Boolean(sentMail.length)
+    if err?
+      log.error "Error finding mail sent for task #{@mailTaskName} and user #{candidate._id}!"
+      sentEmailFilterCallback true
+    else
+      sentEmailFilterCallback Boolean(sentMail.length)
 
 findEmployersSignedUpAfterDate = (dateObject, cb) ->
   countParameters =

      sendwithus.api.send context, (err, result) ->
        log.error "Error sending candidate update reminder email: #{err} with result #{result}" if err
        sendEmailCallback null

generateWeekOffset = (originalDate, numberOfWeeks) ->
  return (new Date(originalDate.getTime() - numberOfWeeks * 7 * 24 * 60 * 60 * 1000)).toISOString()

candidateUpdateProfileTask = ->
  mailTaskName = "candidateUpdateProfileTask"
  lockDurationMs = 6000
  currentDate = new Date()
  timeRanges = []
  for weekPair in [[4, 2,'two weeks'], [8, 4, 'four weeks'], [8, 52, 'eight weeks']]
    timeRanges.push 
      start: generateWeekOffset currentDate, weekPair[0]
      end: generateWeekOffset currentDate, weekPair[1]
      name: weekPair[2]
  lockManager.setLock mailTaskName, lockDurationMs, (err, lockResult) ->
    if err? then return log.error "Error getting a task lock!"
    async.each timeRanges, emailTimeRange.bind(mailTaskName: mailTaskName), (err) ->
      if err then log.error JSON.stringify err else log.info "Sent candidate update reminders!"
      lockManager.releaseLock mailTaskName, (err, result) -> if err? then return log.error err
        
### End Candidate Update Reminder Task ###
### Internal Candidate Update Reminder Email ###

emailInternalCandidateUpdateReminder = (cb) ->
  currentTime = new Date()
  beginningOfUTCDay = new Date()
  beginningOfUTCDay.setUTCHours(0,0,0,0)

      sendwithus.api.send context, (err, result) ->
        log.error "Error sending employer candidates available email: #{err} with result #{result}" if err
        cb null

### End Employer New Candidates Available Email ###

