rake任务调整

dev_course
cxt 6 years ago
parent b56b288401
commit 1b830ac11f

@ -458,9 +458,9 @@ class HomeworkCommonsController < ApplicationController
tip_exception("发布时间不能为空") if setting[:publish_time].blank?
tip_exception("截止时间不能为空") if setting[:end_time].blank?
# 如果该发布规则 没有已发布的分班则需判断发布时间
tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0
tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now)
tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now)
tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time]
tip_exception("截止时间不能早于课堂结束时间") if setting[:end_time] > strf_time(@course.end_date.end_of_day)
@ -585,9 +585,9 @@ class HomeworkCommonsController < ApplicationController
# anonymous_comment :true 是启用false 是不启用
if params[:anonymous_comment]
tip_exception("匿评开启时间不能为空") if params[:evaluation_start].blank?
tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] <= strf_time(@homework.end_time)
tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] < strf_time(@homework.end_time)
tip_exception("匿评结束时间不能为空") if params[:evaluation_end].blank?
tip_exception("匿评截止时间不能早于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start]
tip_exception("匿评截止时间必须晚于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start]
tip_exception("匿评截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:evaluation_end] >
strf_time(@course.end_date.end_of_day)
tip_exception("匿评数必须为正整数") if params[:evaluation_num].blank? || params[:evaluation_num].to_i < 1
@ -614,7 +614,7 @@ class HomeworkCommonsController < ApplicationController
# 匿评未截止时可以更新匿评结束时间
if @homework_detail_manual.comment_status < 4
tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank?
tip_exception("匿评截止时间不能早于匿评开启时间") if @homework.anonymous_comment &&
tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment &&
params[:evaluation_end] <= params[:evaluation_start]
tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment &&
@course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day)

@ -15,9 +15,9 @@ class ExercisePublishTask
tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if exercise.unified_setting
course.student.find_each do |student|
course.students.find_each do |student|
tid_str += "," if tid_str != ""
tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
end
if tid_str != ""
@ -25,7 +25,7 @@ class ExercisePublishTask
ActiveRecord::Base.connection.execute tid_sql
end
if exercise.exercise_users.count == 0
if exercise.exercise_users.size == 0
str = ""
course.students.find_each do |student|
str += "," if str != ""

@ -5,37 +5,41 @@ namespace :exercise_deadline_warn do
task :deadline_warn => :environment do
puts "--------------------------------exercise_nearly_end start"
# 统一设置发布时间的测验
exercises = Exercise.where("exercise_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800)
exercises = Exercise.where("exercise_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
exercises.each do |exercise|
if exercise.tidings.where(:parent_container_type => "NearlyEnd").count == 0
if exercise.tidings.where(parent_container_type: "NearlyEnd").count == 0
course = exercise.course
tid_str = ""
exercise.exercise_users.where(:commit_status => 0).find_each do |student|
exercise.exercise_users.where(commit_status: 0).find_each do |student|
tid_str += "," if tid_str != ""
tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd',
#{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id,
parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql
end
end
end
# 分组设置发布时间的测验
exercise_group_settings = ExerciseGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800)
exercise_group_settings = ExerciseGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
exercise_group_settings.each do |exercise_group|
exercise = exercise_group.exercise
if exercise.present?
course = exercise.course
members = course.course_members.where(:course_group_id => exercise_group.course_group_id)
if exercise.tidings.where(:parent_container_type => "NearlyEnd", :user_id => members.map(&:user_id)).count == 0
members = course.students.where(course_group_id: exercise_group.course_group_id)
if exercise.tidings.where(parent_container_type: "NearlyEnd", user_id: members.pluck(:user_id)).count == 0
tid_str = ""
exercise.exercise_users.where(:commit_status => 0, :user_id => members.map(&:user_id)).find_each do |member|
exercise.exercise_users.where(commit_status: 0, user_id: members.pluck(:user_id)).find_each do |member|
tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd',
#{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id,
parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql
end
end

@ -30,7 +30,7 @@ namespace :graduation_task do
end
task :nearly_end => :environment do
tasks = GraduationTask.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800)
tasks = GraduationTask.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
tasks.each do |task|
if task.tidings.where(parent_container_type: "NearlyEnd").count == 0
course = task.course

@ -4,7 +4,7 @@ namespace :homework_endtime do
desc "send a message for Job deadline"
task :message => :environment do
# 统一设置发布时间的作业
homeworks = HomeworkCommon.where("unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800)
homeworks = HomeworkCommon.includes(:course).where("unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
homeworks.each do |homework|
if homework.tidings.where(:parent_container_type => "NearlyEnd").count == 0
course = homework.course
@ -25,7 +25,7 @@ namespace :homework_endtime do
end
# 分组设置发布时间的作业
homework_group_settings = HomeworkGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800)
homework_group_settings = HomeworkGroupSetting.includes(:homework_common).where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600)
homework_group_settings.each do |homework_group|
homework = homework_group.homework_common
if homework.present?
@ -52,8 +52,8 @@ namespace :homework_endtime do
# 匿评截止时间快到了
task :evaluation_nearly_end => :environment do
homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 3 and evaluation_end <=?
and evaluation_end > ? ", Time.now + 86400, Time.now + 82800)
homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("homework_detail_manuals.comment_status = 3 and evaluation_end <=?
and evaluation_end > ? ", Time.now + 86400, Time.now + 84600)
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
if homework_common.present?
@ -85,7 +85,7 @@ namespace :homework_endtime do
# 匿评申诉截止时间快到了
task :appeal_nearly_end => :environment do
homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 4 and appeal_time <=?
and appeal_time > ?", Time.now + 86400, Time.now + 82800)
and appeal_time > ?", Time.now + 86400, Time.now + 84600)
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
if homework_common.present?

@ -12,7 +12,7 @@ namespace :homework_evaluation do
task :start_evaluation => :environment do
Rails.logger.info("log--------------------------------start_evaluation start")
puts "--------------------------------start_evaluation start"
homework_detail_manuals = HomeworkDetailManual.where("evaluation_start <= '#{Time.now}' and
homework_detail_manuals = HomeworkDetailManual.includes(homework_common: :course).where("evaluation_start <= '#{Time.now}' and
(homework_detail_manuals.comment_status < 3)")
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
@ -110,7 +110,7 @@ namespace :homework_evaluation do
#自动关闭匿评的任务
task :end_evaluation => :environment do
homework_detail_manuals = HomeworkDetailManual.where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3")
homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3")
homework_detail_manuals.each do |homework_detail_manual|
homework_common = homework_detail_manual.homework_common
if homework_common.anonymous_comment #开启匿评状态才可关闭匿评

@ -6,8 +6,8 @@ namespace :homework_publishtime do
# 作业的分班设置时间
def homework_group_setting homework, group_id
setting = nil
if homework.homework_group_settings.where(:course_group_id => group_id).first
setting = homework.homework_group_settings.where(:course_group_id => group_id).first
if homework.homework_group_settings.where(course_group_id: group_id).first
setting = homework.homework_group_settings.where(course_group_id: group_id).first
else
setting = homework
end

@ -116,11 +116,7 @@ namespace :poll_publish do
polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900)
polls.each do |poll|
poll.update_column('polls_status', 3)
poll.poll_users.each do |poll_user|
if poll_user.commit_status == 0 && poll_user.start_at.present?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end
end
poll.poll_users.where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now)
end
#2.分班设置的截止
@ -132,13 +128,13 @@ namespace :poll_publish do
if poll&.end_time <= Time.now
poll.update_column('polls_status', 3)
end
users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id)
poll_users = poll.poll_users.where(:user_id => users.map(&:user_id))
poll_users.each do |poll_user|
if poll_user.commit_status == 0 && !poll_user.start_at.nil?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end
end
users = poll.course.course_members.where(course_group_id: poll_setting.course_group_id)
poll.poll_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now)
# poll_users.each do |poll_user|
# if poll_user.commit_status == 0 && !poll_user.start_at.nil?
# poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
# end
# end
end
# PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting|

@ -5,9 +5,7 @@ namespace :resource_publish do
task :publish => :environment do
Rails.logger.info("log--------------------------------resource_publish start")
attachments = Attachment.where("publish_time < '#{Time.now}' and is_publish = 0")
attachments.each do |attachment|
attachment.update_attributes(:is_publish => 1)
end
attachments.update_all(is_publish: 1)
Rails.logger.info("log--------------------------------resource_publish end")
end
end
Loading…
Cancel
Save