Fixed foodsoft rake tasks.

This commit is contained in:
benni 2012-08-27 08:38:43 +02:00
parent ea547c84f0
commit 971e80b505
3 changed files with 7 additions and 15 deletions

View file

@ -5,7 +5,6 @@ class Task < ActiveRecord::Base
scope :non_group, :conditions => { :workgroup_id => nil, :done => false } scope :non_group, :conditions => { :workgroup_id => nil, :done => false }
scope :done, :conditions => {:done => true}, :order => "due_date DESC" scope :done, :conditions => {:done => true}, :order => "due_date DESC"
scope :upcoming, lambda { |*args| {:conditions => ["done = 0 AND due_date = ?", (args.first || 7.days.from_now)]} }
# form will send user in string. responsibilities will added later # form will send user in string. responsibilities will added later
attr_protected :users attr_protected :users

View file

@ -4,17 +4,14 @@
namespace :foodsoft do namespace :foodsoft do
desc "Notify users of upcoming tasks" desc "Notify users of upcoming tasks"
task :notify_upcoming_tasks => :environment do task :notify_upcoming_tasks => :environment do
tasks = Task.find :all, :conditions => ["done = ? AND due_date = ?", false, 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 .." puts "Send notifications for #{task.name} to .."
for user in task.users for user in task.users
if user.settings['notify.upcoming_tasks'] == 1 begin
begin Mailer.upcoming_tasks(user, task).deliver if user.settings['notify.upcoming_tasks'] == 1
puts "#{user.email}.." rescue
Mailer.upcoming_tasks(user, task).deliver puts "deliver aborted for #{user.email}.."
rescue
puts "deliver aborted for #{user.email}.."
end
end end
end end
end end
@ -22,7 +19,7 @@ namespace :foodsoft do
desc "Create upcoming workgroups tasks (next 3 to 7 weeks)" desc "Create upcoming workgroups tasks (next 3 to 7 weeks)"
task :create_upcoming_weekly_tasks => :environment do task :create_upcoming_weekly_tasks => :environment do
workgroups = Workgroup.all :conditions => {:weekly_task => true} workgroups = Workgroup.where(weekly_task: true)
for workgroup in workgroups for workgroup in workgroups
puts "Create weekly tasks for #{workgroup.name}" puts "Create weekly tasks for #{workgroup.name}"
workgroup.next_weekly_tasks[3..5].each do |date| workgroup.next_weekly_tasks[3..5].each do |date|
@ -36,7 +33,7 @@ namespace :foodsoft do
desc "Notify workgroup of upcoming weekly task" desc "Notify workgroup of upcoming weekly task"
task :notify_users_of_weekly_task => :environment do task :notify_users_of_weekly_task => :environment do
for workgroup in Workgroup.all for workgroup in Workgroup.all
for task in workgroup.tasks.all(:conditions => ["due_date = ?", 7.days.from_now.to_date]) for task in workgroup.tasks.where(due_date: 7.days.from_now.to_date)
unless task.enough_users_assigned? unless task.enough_users_assigned?
puts "Notify workgroup: #{workgroup.name} for task #{task.name}" puts "Notify workgroup: #{workgroup.name} for task #{task.name}"
for user in workgroup.users for user in workgroup.users

View file

@ -1,4 +0,0 @@
desc "Deliver messages as emails"
task :send_emails => :environment do
Message.send_emails
end