作业截止时间消息通知:

1、时间区段设置为24小时
2、只进行一次消息提醒
This commit is contained in:
huang 2015-09-11 11:02:40 +08:00
parent 08c222266a
commit bb3fc97528
1 changed files with 6 additions and 4 deletions

View File

@ -4,11 +4,13 @@ namespace :homework_endtime do
desc "send a message for Job deadline"
task :message => :environment do
current_day = Date.today.day
homework_commons = HomeworkCommon.where("end_time >?",Date.today)
homework_commons = HomeworkCommon.where("end_time >=?",Date.today)
homework_commons.each do |homework_common|
if homework_common.end_time.day - Date.today.day < 2 && homework_common.end_time.year == Date.today.year
homework_common.course.student.each do |s|
homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :status => true)
if CourseMessage.where("course_message_type =? and course_message_id =? and status =?", "HomeworkCommon", homework_common.id, 1).first.nil?
if homework_common.end_time.day - Date.today.day < 2 && homework_common.end_time.year == Date.today.year
homework_common.course.student.each do |s|
homework_common.course_messages << CourseMessage.new(:user_id => s.student_id, :course_id => homework_common.course_id, :viewed => false, :status => true)
end
end
end
end