fix delayed message validation for alerts

fixes CNVS-15426

test plan:
- enable account alerts in account settings
- enroll a teacher in a course
- make sure the teacher has a verified email address
- visit the teacher's notification preferences page to make sure there is
  a notification policy set up for the alert notification.  confusingly, this
  is not the same as the "Alert" section on the page, this notification policy
  actually cannot be customized, but visiting the page will create it if it
  doesn't already exist.
- the annoying thing about this alert notification policy is setup is that it
  is set up to be a 'daily' policy, and it can't be customized.  this means
  that even after the job runs and creates the message successfully, it won't
  actually be sent until the following daily batch. to fix this for testing,
  you can make the notification policy immediate by running the following in
  a rails console:
    ```
    NotificationPolicy.
      where(:notification_id => Notification.by_name("Alert")).
      update_all(:frequency => "immediately")
    ```
- now set up an alert and trigger the conditions for the alert
- alert messages are only computed once per day at 11:30 utc. since this is an
  inconvenient time to have a patchset checked out, the easiest way to make
  this happen manually is to run the following in a rails conosle:
    `Alerts::DelayedAlertSender.process`
  however, be aware that this job sets a redis key after it runs to make sure
  notifications don't get sent twice to the same person, so if you do need to run
  it twice in one day for some reason, clear redis between runs.
- the alert message should actually be sent.  if you set up a real email
  address you should receive the message, or you can check that it was sent by
  using the "View Notifications" tab in the admin tools section of the account.

Change-Id: Ia3ca030da1896539c6ca193b87c1ce9d3b936ef9
Reviewed-on: https://gerrit.instructure.com/40919
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Liz Abinante <labinante@instructure.com>
QA-Review: Anna Koalenz <akoalenz@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Simon Williams 2014-09-10 15:42:24 -06:00
parent 44cccdb7d8
commit f154fb1226
2 changed files with 19 additions and 1 deletions

View File

@ -27,7 +27,8 @@ class DelayedMessage < ActiveRecord::Base
'SubmissionComment', 'Submission', 'ConversationMessage', 'Course', 'DiscussionTopic',
'Enrollment', 'Attachment', 'AssignmentOverride', 'Quizzes::QuizSubmission', 'GroupMembership',
'CalendarEvent', 'WikiPage', 'AssessmentRequest', 'AccountUser', 'WebConference', 'Account', 'User',
'AppointmentGroup', 'Collaborator', 'AccountReport', 'Quizzes::QuizRegradeRun', 'CommunicationChannel']
'AppointmentGroup', 'Collaborator', 'AccountReport', 'Quizzes::QuizRegradeRun', 'CommunicationChannel',
'Alert']
belongs_to :communication_channel
attr_accessible :notification, :notification_policy, :frequency,
:communication_channel, :linked_name, :name_of_topic, :link, :summary,

View File

@ -289,5 +289,22 @@ module Alerts
DelayedAlertSender.evaluate_for_course(@course, nil)
end
end
it "should work end to end" do
Notification.unstub(:by_name)
Notification.create(:name => "Alert")
course_with_teacher(:active_all => 1)
student_in_course(:active_all => 1)
@student.communication_channels.create(:path => "student@example.com").confirm!
alert = @course.alerts.build(:recipients => [:student])
alert.criteria.build(:criterion_type => 'Interaction', :threshold => 7)
alert.save!
@course.start_at = Time.now - 30.days
expect {
DelayedAlertSender.evaluate_for_course(@course, nil)
}.to change(DelayedMessage, :count).by(1)
end
end
end