发布测验的时候发布消息

This commit is contained in:
lizanle 2015-12-04 11:21:41 +08:00
parent e3c594a7ca
commit 03588ca88d
2 changed files with 4 additions and 22 deletions

View File

@ -6,6 +6,10 @@ namespace :exercise_publish do
exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises.each do |exercise|
exercise.update_column('exercise_status', 2)
course = exercise.course
course.members.each do |m|
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
end
end
end

View File

@ -1,22 +0,0 @@
#coding=utf-8
namespace :exercise_publishtime do
desc "start publish exercise"
task :publish => :environment do
exercises = Exercise.where("date_format(publish_time,'%Y-%m-%d')= '#{Date.today}'")
exercises.each do |exercise|
if exercise.exercise_status == 1 #未发布
exercise.update_column('exercise_status', 2) #改为发布
course = exercise.course
course.members.each do |m|
exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
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
end
end