-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Job for sending survey notifications to clients who did not receive o…
…ne (#4395) * Implement and run a job to send survey notification to clients who did not receive one
- Loading branch information
1 parent
e901f89
commit 4a917f8
Showing
3 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
app/controllers/concerns/state_file/survey_links_concern.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |