socialforge/lib/tasks/contest_work_endtime.rake

39 lines
1.9 KiB
Ruby

#coding=utf-8
namespace :contest_work_endtime do
desc "send a message for work deadline"
task :message => :environment do
puts "--------------------------------contest_work_endtime start"
contrast_time = Time.now - 86400
homework_commons = Work.where("end_time >=? and end_time <=?",contrast_time, Time.now)
homework_commons.each do |homework_common|
if ContestMessage.where("contest_message_type =? and contest_message_id =? and status =?", "Work", homework_common.id, 1).first.nil?
homework_common.contest.contestants.each do |s|
homework_common.contest_messages << ContestMessage.new(:user_id => s.student_id, :contest_id => homework_common.contest_id, :viewed => false, :status => 1)
# 发送邮件通知
# Mailer.homework_endtime__added(homework_common, s.student_id).deliver
end
end
end
puts "--------------------------------contest_work_endtime end"
end
task :evaluation_message => :environment do
puts "--------------------------------contest_work_evaluation_endtime start"
contrast_time = Time.now - 86400
works = Work.where(:online_evaluation => true, :work_status => 3)
work_ids = works.blank? ? "(-1)" : "(" + works.map{|work| work.id}.join(",") + ")"
work_detail_manuals = WorkDetailManual.where("evaluation_end >=? and evaluation_end <= '#{Date.today}' and work_id in #{work_ids}",contrast_time)
work_detail_manuals.each do |work_detail|
work = work_detail.work
if ContestMessage.where("contest_message_type =? and contest_message_id =? and status =?", "Work", work.id, 5).first.nil?
work.contest.contest_judges.each do |s|
work.contest_messages << ContestMessage.new(:user_id => s.user_id, :contest_id => work.contest_id, :viewed => false, :status => 5)
end
end
end
puts "--------------------------------contest_work_evaluation_endtime end"
end
end