Skip to content

Commit

Permalink
Job for sending survey notifications to clients who did not receive o…
Browse files Browse the repository at this point in the history
…ne (#4395)

* Implement and run a job to send survey notification to clients who did not receive one
  • Loading branch information
rickreyhsig authored Mar 21, 2024
1 parent e901f89 commit 4a917f8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
15 changes: 15 additions & 0 deletions app/controllers/concerns/state_file/survey_links_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module StateFile
module SurveyLinksConcern
extend ActiveSupport::Concern
def survey_link(intake)
case intake.state_code
when 'ny'
'https://codeforamerica.co1.qualtrics.com/jfe/form/SV_3pXUfy2c3SScmgu'
when 'az'
'https://codeforamerica.co1.qualtrics.com/jfe/form/SV_7UTycCvS3UEokey'
else
''
end
end
end
end
16 changes: 3 additions & 13 deletions app/jobs/send_survey_notification_job.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
class SendSurveyNotificationJob < ApplicationJob
include StateFile::SurveyLinksConcern
def perform(intake, submission)
StateFile::MessagingService.new(
intake: intake,
submission: submission,
message: StateFile::AutomatedMessage::SurveyNotification,
body_args: { survey_link: survey_link(intake) }).send_message
body_args: { survey_link: survey_link(intake) }
).send_message
end

def priority
PRIORITY_LOW
end

private
def survey_link(intake)
case intake.state_code
when 'ny'
'https://codeforamerica.co1.qualtrics.com/jfe/form/SV_3pXUfy2c3SScmgu'
when 'az'
'https://codeforamerica.co1.qualtrics.com/jfe/form/SV_7UTycCvS3UEokey'
else
''
end
end
end
22 changes: 22 additions & 0 deletions lib/tasks/send_survey_notifications.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace :survey_notifications do
desc 'Send survey notifications to all accepted returns prior to our shipping this feature'
task 'send' => :environment do
include StateFile::SurveyLinksConcern
BATCH_SIZE = 10
accepted_submissions = EfileSubmission.joins(:efile_submission_transitions)
.where("efile_submission_transitions.to_state = 'accepted'")
.where.not("message_tracker #> '{messages.state_file.survey_notification}' IS NOT NULL")

accepted_submissions.each_slice(BATCH_SIZE) do |batch|
batch.each do |submission|
puts "Sending survey notification to #{submission.id}"
StateFile::MessagingService.new(
intake: submission.data_source,
submission: submission,
message: StateFile::AutomatedMessage::SurveyNotification,
body_args: { survey_link: survey_link(submission.data_source) }
).send_message
end
end
end
end

0 comments on commit 4a917f8

Please sign in to comment.