Avoid send messages so STDOUT in rake silen mode.

This commit is contained in:
Benjamin Meichsner 2013-09-25 11:57:22 +02:00
parent 2060261c89
commit 975bcdec3a
2 changed files with 16 additions and 5 deletions

View file

@ -5,12 +5,12 @@ namespace :foodsoft do
task :notify_upcoming_tasks => :environment do task :notify_upcoming_tasks => :environment do
tasks = Task.where(done: false, due_date: 1.day.from_now.to_date) tasks = Task.where(done: false, due_date: 1.day.from_now.to_date)
for task in tasks for task in tasks
puts "Send notifications for #{task.name} to .." say "Send notifications for #{task.name} to .."
for user in task.users for user in task.users
begin begin
Mailer.upcoming_tasks(user, task).deliver if user.settings.notify['upcoming_tasks'] == 1 Mailer.upcoming_tasks(user, task).deliver if user.settings.notify['upcoming_tasks'] == 1
rescue rescue
puts "deliver aborted for #{user.email}.." say "deliver aborted for #{user.email}.."
end end
end end
end end
@ -27,7 +27,7 @@ namespace :foodsoft do
begin begin
Mailer.not_enough_users_assigned(task, user).deliver Mailer.not_enough_users_assigned(task, user).deliver
rescue rescue
puts "deliver aborted for #{user.email}" say "deliver aborted for #{user.email}"
end end
end end
end end
@ -47,3 +47,8 @@ namespace :foodsoft do
end end
end end
end end
# Helper
def say(message)
puts message unless Rake.application.options.silent
end

View file

@ -8,7 +8,7 @@ namespace :multicoops do
task :run => :environment do task :run => :environment do
task_to_run = ENV['TASK'] task_to_run = ENV['TASK']
FoodsoftConfig.each_coop do |coop| FoodsoftConfig.each_coop do |coop|
puts "Run '#{task_to_run}' for #{coop}" say "Run '#{task_to_run}' for #{coop}"
Rake::Task[task_to_run].execute Rake::Task[task_to_run].execute
end end
end end
@ -17,8 +17,14 @@ namespace :multicoops do
task :run_single => :environment do task :run_single => :environment do
task_to_run = ENV['TASK'] task_to_run = ENV['TASK']
FoodsoftConfig.select_foodcoop ENV['FOODCOOP'] FoodsoftConfig.select_foodcoop ENV['FOODCOOP']
puts "Run '#{task_to_run}' for #{ENV['FOODCOOP']}" say "Run '#{task_to_run}' for #{ENV['FOODCOOP']}"
Rake::Task[task_to_run].execute Rake::Task[task_to_run].execute
end end
end end
# Helper
def say(message)
puts message unless Rake.application.options.silent
end