socialforge/lib/tasks/exercise_close_to_deadline_...

21 lines
1.0 KiB
Ruby

#coding=utf-8
#需要在0点以后执行
namespace :exercise_deadline_warn do
desc "exercise deadline warn"
task :deadline_warn => :environment do
#exercise_status 1 未发布 2 已发布 3已截止
exercises = Exercise.where("exercise_status = 2 and date_format(end_time,'%Y-%m-%d')= '#{Date.today}'") #截止日期都是当天 23.59分,所以年月日相等的一定是今晚会截止的测验
exercises.each do |exercise|
course = exercise.course
course.members.each do |m|
#CourseMessage status 1 未发布 status 2 已发布 status 3 已发布快截止了
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) unless m.user.allowed_to?(:as_teacher,m)
end
# if homework.course_acts.size == 0
# homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
# end
# 邮件通知
#Mailer.run.homework_added(homework)
end
end
end