#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") homework_commons = Work.where("work_status = 0 and publish_time <= '#{Date.today}'") homework_commons.each do |homework| homework.update_attribute('work_status', 1) 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) end 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) end Rails.logger.info("log--------------------------------contest_work_publish end") puts "--------------------------------contest_work_publish end" end 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 end