From a548781007a7be95deff4c8ca2d3499d5671acfd Mon Sep 17 00:00:00 2001 From: JoaoFelipe Date: Tue, 21 Jan 2014 23:31:35 -0200 Subject: [PATCH] Issue #12: avoid the execution of notifier on rake tasks --- config/initializers/noifications.rb | 10 ++++++++-- lib/notifier.rb | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config/initializers/noifications.rb b/config/initializers/noifications.rb index 59819d42..f1aee49d 100644 --- a/config/initializers/noifications.rb +++ b/config/initializers/noifications.rb @@ -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 diff --git a/lib/notifier.rb b/lib/notifier.rb index 6dbe4b3b..de470572 100644 --- a/lib/notifier.rb +++ b/lib/notifier.rb @@ -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 => 'sapos@mailinator.com'} first_at = Time.now + 1.second @@ -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 ##########" @@ -59,4 +60,3 @@ def display_notification_info(notification) puts "##################################" end end -