#coding=utf-8 namespace :homework_publishtime do desc "start publish homework and end homework" task :publish => :environment do puts "--------------------------------homework_publish start" Rails.logger.info("log--------------------------------homework_publish start") homework_commons = HomeworkCommon.where("publish_time = '#{Date.today}'") homework_commons.each do |homework| homework_detail_manual = homework.homework_detail_manual if homework_detail_manual.comment_status == 0 homework_detail_manual.update_column('comment_status', 1) if homework.homework_type != 3 students = homework.course.student if !homework.course.nil? && !students.empty? name = homework.name name_str = name + "的作品提交" str = "" students.each do |student| if str != "" str += "," end str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{Time.now}', '#{Time.now}')" end sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str ActiveRecord::Base.connection.execute sql end end course = homework.course course.members.each do |m| homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => nil) 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 Rails.logger.info("log--------------------------------homework_publish end") puts "--------------------------------homework_publish end" end # task :end => :environment do # puts "--------------------------------homework_publish_end start" # Rails.logger.info("log--------------------------------homework_publish_end start") # homework_commons = HomeworkCommon.where("end_time = '#{Date.today}'") # homework_commons.each do |homework| # if homework.anonymous_comment == 1 # homework_detail_manual = homework.homework_detail_manual # if homework_detail_manual.comment_status == 1 # homework_detail_manual.update_column('comment_status', 3) # end # end # end # Rails.logger.info("log--------------------------------homework_publish_end end") # puts "--------------------------------homework_publish_end end" # end end