2015-12-04 10:56:16 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
namespace :exercise_deadline_warn do
|
|
|
|
desc "exercise deadline warn"
|
|
|
|
task :deadline_warn => :environment do
|
2015-12-04 13:39:17 +08:00
|
|
|
#exercise_status 1 未发布 2 已发布 3已截止
|
2015-12-04 11:24:24 +08:00
|
|
|
exercises = Exercise.where("exercise_status = 2 and date_format(end_time,'%Y-%m-%d')= '#{Date.today}'") #截止日期都是当天 23.59分,所以年月日相等的一定是今晚会截止的测验
|
2015-12-04 10:56:16 +08:00
|
|
|
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
|