Skip to content

Commit

Permalink
Issue #12: avoid the execution of notifier on rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoFelipe committed Jan 22, 2014
1 parent b508dff commit a548781
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions config/initializers/noifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
notifier = Notifier.instance

notifier.new_notification do
phase_completions = PhaseCompletion.where("due_date < ? AND phase_id = ?", 730.days.since(Date.today), 1)
phase_completions = PhaseCompletion.where("due_date < ? AND phase_id = ?", 30.days.since(Date.today), 1)
notifications = []

phase_completions.each do |phase_completion|
notification = {:to => phase_completion.enrollment.student.email, :subject => "Test", :body => "Test"}
unless phase_completion.enrollment.student.email.nil?
notification = {
:to => phase_completion.enrollment.student.email,
:subject => "Test",
:body => "Test"
}
end
notifications << notification
end
notifications
Expand Down
4 changes: 2 additions & 2 deletions lib/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Notifier
def initialize
@notifications = []
@options = {}

return if $rails_rake_task
if Rails.env.development? or Rails.env.test?
@options = {:to => '[email protected]'}
first_at = Time.now + 1.second
Expand Down Expand Up @@ -50,6 +50,7 @@ def send_emails
end
end

#ToDo: Use rails logger
def display_notification_info(notification)
puts "\n#{Time.now.strftime('%Y/%m/%d %H:%M:%S')}"
puts "########## Notification ##########"
Expand All @@ -59,4 +60,3 @@ def display_notification_info(notification)
puts "##################################"
end
end

0 comments on commit a548781

Please sign in to comment.