lib/model_patches.rb
# Send an email with a link to the survey two weeks after a request was made,
# if the user has not already completed the survey.
Send an email with a link to the survey two weeks after a request was made,
if the user has not already completed the survey.
Send an email with a link to the survey two weeks after a request was made if the user has not already completed the survey .
def alert_survey
        info_requests = InfoRequest.where(
          " created_at between now() - '2 weeks + 1 day'::interval and now() - '2 weeks'::interval" +
          " and user_id is not null" +
          " and not exists (" +
          "     select *" +
          "     from user_info_request_sent_alerts" +
          "     where user_id = info_requests.user_id" +
          "      and  alert_type = 'survey_1'" +
          " )"
        ).includes(:user)
        sent_to = []
        for info_request in info_requests
          logger.debug "[alert_survey] Considering #{info_request.user.url_name}"
          next if !info_request.user.can_send_survey? || sent_to.include?(info_request.user_id)
          store_sent = UserInfoRequestSentAlert.new
          store_sent.info_request = info_request
          store_sent.user = info_request.user
          store_sent.alert_type = 'survey_1'
          store_sent.info_request_event_id = info_request.info_request_events[0].id
          sent_to << info_request.user_id
          RequestMailer.survey_alert(info_request).deliver_now
          store_sent.save!
        end
      end
def alert_survey info_requests = InfoRequest . where ( " created_at between now() - '2 weeks + 1 day'::interval and now() - '2 weeks'::interval" + " and user_id is not null" + " and not exists (" + "     select *" + "     from user_info_request_sent_alerts" + "     where user_id = info_requests.user_id" + "      and  alert_type = 'survey_1'" + " )" ) . includes ( :user ) sent_to = [ ] for info_request in info_requests logger . debug "[alert_survey] Considering #{info_request.user.url_name}" next if ! info_request . user . can_send_survey? || sent_to . include? ( info_request . user_id ) store_sent = UserInfoRequestSentAlert . new store_sent . info_request = info_request store_sent . user = info_request . user store_sent . alert_type = 'survey_1' store_sent . info_request_event_id = info_request . info_request_events [ 0 ] . id sent_to << info_request . user_id RequestMailer . survey_alert ( info_request ) . deliver_now store_sent . save! end end
Send an email with a link to the survey two weeks after a request was made,
if the user has not already completed the survey.
Send an email with a link to the survey two weeks after a request was made if the user has not already completed the survey .
# Exclude requests made by users who have already been alerted about the survey # TODO: change the initial query to iterate over users rather # than info_requests rather than using an array to check whether # we're about to send multiple emails to the same user_id # Exclude users who have already completed the survey or # have already been sent a survey email in this run