From 3f9c722c98faeaa9b62e5d38b47375f977e9d3f0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 15 Aug 2019 17:34:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- lib/tasks/public_course.rake | 99 +++++++++++++++++++++++ lib/tasks/publick_course.rake | 25 ------ 3 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 lib/tasks/public_course.rake delete mode 100644 lib/tasks/publick_course.rake diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index db6ae7b57..49fe9ca50 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -239,7 +239,7 @@ class ApplicationController < ActionController::Base uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) if !User.current.logged? && Rails.env.development? - User.current = User.find 57703 + User.current = User.find 12 end diff --git a/lib/tasks/public_course.rake b/lib/tasks/public_course.rake new file mode 100644 index 000000000..9c5065982 --- /dev/null +++ b/lib/tasks/public_course.rake @@ -0,0 +1,99 @@ +#coding=utf-8 +# 执行示例 bundle exec rake public_course:student args=149,2903 +# args 第一个参数是subject_id,第二个参数是课程course_id +# 第一期时间:2018-12-16 至2019-03-31 +# 第二期时间:2019-04-07 至2019-07-28 +# +# 这次学习很有收获,感谢老师提供这么好的资源和细心的服务🎉🎉🎉 +# + +desc "同步精品课数据" +namespace :public_course do + subject_id = ENV['args'].split(",")[0] # 对应课程的id + course_id = ENV['args'].split(",")[1] # 对应课堂的id + status = ENV['args'].split(",")[2] # 表示相应的期数 + type = ENV['args'].split(",")[3] # 表示课程模块 + + if status.to_i == 1 + start_time = '2018-12-16' + end_time = '2019-04-01' + elsif status.to_i == 2 + start_time = '2019-04-07' + end_time = '2019-07-28' + else + # 这种情况是取所有的 + start_time = '2015-01-01' + end_time = '2022-07-28' + end + + task :student => :environment do + puts "subject_id is #{subject_id}" + puts "course_id is #{course_id}" + + user_ids = Myshixun.find_by_sql("select distinct(user_id) from myshixuns where shixun_id in (select shixun_id from stage_shixuns + where stage_id in (select id from stages where subject_id=#{subject_id}))").map(&:user_id) + puts user_ids + if user_ids.present? + user_ids.each do |user_id| + puts user_id + begin + CourseMember.create!(course_id: course_id, user_id: user_id, role: 4) + rescue Exception => e + Rails.logger() + end + end + end + end + + # + task :message => :environment do + discusses = Discuss.find_by_sql("select content, user_id, created_on, updated_on from discusses where dis_id in (select shixun_id from stage_shixuns where + stage_id in (select id from stages where subject_id=#{subject_id})) and created_at > #{start_time} and + created_at<#{end_time}") + discusses.find_each do |discuss| + puts discuss.user_id + puts discuss.content + # 回复帖子 + # 讨论区发布帖子 + # Message.create!(board: @message.board, root_id: @message.root_id || @message.id, + # author: current_user, parent: @message, + # message_detail_attributes: { + # content: params[:content] + # }) + end + end + + + # 更新某个课程的某类时间 + # 执行示例 bundle exec rake public_course:student tiems=149,2903 + task :time => :environment do + course_id = ENV['args'].split(",")[0] # 对应课堂的id + satus = ENV['args'].split(",")[1] + + course = Course.find(course_id) + + hour = (6..24).to_a.sample(1).first + min = rand(60) + sec = rand(60) + + start_time = Date.parse(start_time) + end_time = Date.parse(end_time) + date = (start_time..end_time).to_a.sample(1).first + + time = "#{date} #{min_swith(hour)}:#{min_swith(min)}:#{min_swith(sec)}" + + puts time + case type + when 1 + # 讨论区 + + end + + end + + def min_swith(time) + puts time + return time < 9 ? "0#{time}" : time + end +end + diff --git a/lib/tasks/publick_course.rake b/lib/tasks/publick_course.rake deleted file mode 100644 index 532e32369..000000000 --- a/lib/tasks/publick_course.rake +++ /dev/null @@ -1,25 +0,0 @@ -#coding=utf-8 -# 执行示例 bundle exec rake public_course:student args=149,2903 -# args 第一个参数是subject_id,第二个参数是课程course_id - -desc "同步精品课数据" -namespace :public_course do - task :student => :environment do - - - subject_id = ENV['args'].split(",").first - course_id = ENV['args'].split(",").last - puts "subject_id is #{subject_id}" - puts "course_id is #{course_id}" - - user_ids = Myshixun.find_by_sql("select distinct(user_id) from myshixuns where shixun_id in (select shixun_id from stage_shixuns - where stage_id in (select id from stages where subject_id=#{subject_id}))").map(&:user_id) - puts user_ids - if user_ids.present? - user_ids.each do |user_id| - puts user_id - CourseMember.create!(course_id: course_id, user_id: user_id, role: 4) - end - end - end -end \ No newline at end of file From e6b26ee6cbec2fd196ad913224df0ce4d96ec030 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 15 Aug 2019 18:03:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=9C=A8=E5=86=B7?= =?UTF-8?q?=E5=8C=BA=E5=90=8E=E8=87=AA=E5=8A=A8=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 63 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 828198def..c7a598a43 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -498,44 +498,41 @@ class GamesController < ApplicationController rescue Exception => e # 思路: 异常首先应该考虑去恢复 # retry为1表示已经轮训完成后还没有解决问题,这个时候需要检测异常 - if params[:retry].to_i == 1 - begin - # 如果模板没有问题,则通过中间层检测实训仓库是否异常 - # 监测版本库HEAD是否存在,不存在则取最新的HEAD - gitUrl = repo_url @myshixun.repo_path - gitUrl = Base64.urlsafe_encode64(gitUrl) - shixun_tomcat = edu_setting('cloud_bridge') - rep_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}"} - # 监测版本库HEAD是否存在,不存在则取最新的HEAD - uri = "#{shixun_tomcat}/bridge/game/check" - res = uri_post uri, rep_params - uid_logger("repo_content to bridge: res is #{res}") - # res值:0 表示正常;-1表示有错误;-2表示代码版本库没了 - # - if status == 0 && res - # 版本库报错,修复不了 - if res['code'] == -1 || res['code'] == -2 - begin - # GitService.delete_repository(repo_path: @myshixun.repo_path) if res['code'] == -1 - project_fork(@myshixun, @shixun.repo_path, current_user.login) - rescue Exception => e - uid_logger_error("#{e.message}") - tip_exception("#{e.message}") - end + begin + # 如果模板没有问题,则通过中间层检测实训仓库是否异常 + # 监测版本库HEAD是否存在,不存在则取最新的HEAD + gitUrl = repo_url @myshixun.repo_path + gitUrl = Base64.urlsafe_encode64(gitUrl) + shixun_tomcat = edu_setting('cloud_bridge') + rep_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}"} + # 监测版本库HEAD是否存在,不存在则取最新的HEAD + uri = "#{shixun_tomcat}/bridge/game/check" + res = uri_post uri, rep_params + uid_logger("repo_content to bridge: res is #{res}") + # res值:0 表示正常;-1表示有错误;-2表示代码版本库没了 + # + if status == 0 && res + # 版本库报错,修复不了 + if res['code'] == -1 || res['code'] == -2 + begin + # GitService.delete_repository(repo_path: @myshixun.repo_path) if res['code'] == -1 + project_fork(@myshixun, @shixun.repo_path, current_user.login) + rescue Exception => e + uid_logger_error("#{e.message}") + tip_exception("#{e.message}") end end - rescue Exception => e - uid_logger_error(e.message) + end + rescue Exception => e + uid_logger_error(e.message) - if @myshixun.shixun.try(:status) < 2 - tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") - else - # 报错继续retry - tip_exception(-3, "#{e.message}") - end + if @myshixun.shixun.try(:status) < 2 + tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") + else + # 报错继续retry + tip_exception(-3, "#{e.message}") end end - # 有异常,版本库获取不到代码,前端轮训15S后,调用retry == 1 tip_exception(0, e.message) end end