socialforge/lib/tasks/contest_work_publichtime.rake

36 lines
1.6 KiB
Ruby
Raw Normal View History

2016-12-24 18:48:50 +08:00
#coding=utf-8
namespace :contest_work_publishtime do
desc "start publish contest_work and end contest_work"
task :publish => :environment do
puts "--------------------------------contest_work_publish start"
Rails.logger.info("log--------------------------------contest_work_publish start")
2016-12-30 10:30:21 +08:00
homework_commons = Work.where("work_status = 0 and publish_time <= '#{Date.today}'")
2016-12-24 18:48:50 +08:00
homework_commons.each do |homework|
2016-12-30 10:30:21 +08:00
homework.update_attribute('work_status', 1)
2016-12-24 18:48:50 +08:00
2016-12-30 10:30:21 +08:00
contest = homework.contest
contest.contestants.each do |m|
homework.contest_messages << ContestMessage.new(:user_id => m.student_id, :contest_id => contest.id, :viewed => false, :status => nil)
2016-12-24 18:48:50 +08:00
end
2016-12-30 10:30:21 +08:00
if homework.contest_acts.size == 0
homework.contest_acts << ContestActivity.new(:user_id => homework.user_id,:contest_id => homework.contest_id)
end
# 邮件通知
# Mailer.run.homework_added(homework)
2016-12-24 18:48:50 +08:00
end
Rails.logger.info("log--------------------------------contest_work_publish end")
puts "--------------------------------contest_work_publish end"
end
2016-12-30 10:30:21 +08:00
task :end => :environment do
puts "--------------------------------contest_work_publish_end start"
Rails.logger.info("log--------------------------------contest_work_publish_end start")
homework_commons = Work.where("work_status = 1 and end_time <= '#{Date.today}'")
homework_commons.each do |homework|
homework.update_attribute('work_status', 2)
end
Rails.logger.info("log--------------------------------contest_work_publish_end end")
puts "--------------------------------contest_work_publish_end end"
end
2016-12-24 18:48:50 +08:00
end