23 lines
757 B
Ruby
23 lines
757 B
Ruby
#coding=utf-8
|
|
|
|
namespace :exercise_publish do
|
|
desc "publish exercise and end exercise"
|
|
task :publish => :environment 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
|
|
|
|
task :end => :environment do
|
|
exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now)
|
|
exercises.each do |exercise|
|
|
exercise.update_column('exercise_status', 3)
|
|
end
|
|
end
|
|
end
|