2009-01-06 11:49:19 +01:00
|
|
|
# put in here all foodsoft tasks
|
|
|
|
# => :environment loads the environment an gives easy access to the application
|
|
|
|
namespace :foodsoft do
|
2009-02-10 15:07:47 +01:00
|
|
|
desc "Notify users of upcoming tasks"
|
|
|
|
task :notify_upcoming_tasks => :environment do
|
2012-08-27 08:38:43 +02:00
|
|
|
tasks = Task.where(done: false, due_date: 1.day.from_now.to_date)
|
2009-02-10 15:07:47 +01:00
|
|
|
for task in tasks
|
2013-09-30 10:57:54 +02:00
|
|
|
rake_say "Send notifications for #{task.name} to .."
|
2009-02-10 15:07:47 +01:00
|
|
|
for user in task.users
|
2012-08-27 08:38:43 +02:00
|
|
|
begin
|
2013-06-06 03:40:15 +02:00
|
|
|
Mailer.upcoming_tasks(user, task).deliver if user.settings.notify['upcoming_tasks'] == 1
|
2012-08-27 08:38:43 +02:00
|
|
|
rescue
|
2013-09-30 10:57:54 +02:00
|
|
|
rake_say "deliver aborted for #{user.email}.."
|
2009-02-10 15:07:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-11 16:58:31 +01:00
|
|
|
|
2009-08-11 18:10:14 +02:00
|
|
|
desc "Notify workgroup of upcoming weekly task"
|
|
|
|
task :notify_users_of_weekly_task => :environment do
|
|
|
|
for workgroup in Workgroup.all
|
2012-08-27 08:38:43 +02:00
|
|
|
for task in workgroup.tasks.where(due_date: 7.days.from_now.to_date)
|
2009-08-11 18:10:14 +02:00
|
|
|
unless task.enough_users_assigned?
|
|
|
|
puts "Notify workgroup: #{workgroup.name} for task #{task.name}"
|
2009-08-14 13:50:05 +02:00
|
|
|
for user in workgroup.users
|
2013-06-06 03:40:15 +02:00
|
|
|
if user.settings.messages['send_as_email'] == "1" && !user.email.blank?
|
2010-03-20 23:07:55 +01:00
|
|
|
begin
|
2011-05-11 10:53:18 +02:00
|
|
|
Mailer.not_enough_users_assigned(task, user).deliver
|
2010-03-20 23:07:55 +01:00
|
|
|
rescue
|
2013-09-30 10:57:54 +02:00
|
|
|
rake_say "deliver aborted for #{user.email}"
|
2010-03-20 23:07:55 +01:00
|
|
|
end
|
2009-08-14 13:50:05 +02:00
|
|
|
end
|
2009-08-11 18:10:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-28 10:13:54 +01:00
|
|
|
|
|
|
|
desc "Create upcoming periodic tasks"
|
|
|
|
task :create_upcoming_periodic_tasks => :environment do
|
|
|
|
for tg in PeriodicTaskGroup.all
|
|
|
|
if tg.has_next_task?
|
2014-11-23 01:22:50 +01:00
|
|
|
create_until = Date.today + FoodsoftConfig[:tasks_upfront_days].to_i + 1
|
|
|
|
rake_say "creating until #{create_until}"
|
|
|
|
while tg.next_task_date.nil? or tg.next_task_date < create_until
|
2012-11-28 10:13:54 +01:00
|
|
|
tg.create_next_task
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-03-20 23:07:55 +01:00
|
|
|
end
|
2013-09-25 11:57:22 +02:00
|
|
|
|
|
|
|
# Helper
|
2013-09-30 10:57:54 +02:00
|
|
|
def rake_say(message)
|
2013-09-25 11:57:22 +02:00
|
|
|
puts message unless Rake.application.options.silent
|
|
|
|
end
|