日志代码隐藏

problem_set
daiao 6 years ago
parent 8d01646872
commit 382b6cfd63

@ -353,10 +353,10 @@ class ApplicationController < ActionController::Base
# Post请求 # Post请求
def uri_post(uri, params) def uri_post(uri, params)
begin begin
uid_logger("--uri_exec: params is #{params}, url is #{uri}") uid_logger_dubug("--uri_exec: params is #{params}, url is #{uri}")
uri = URI.parse(URI.encode(uri.strip)) uri = URI.parse(URI.encode(uri.strip))
res = Net::HTTP.post_form(uri, params).body res = Net::HTTP.post_form(uri, params).body
logger.info("--uri_exec: .....res is #{res}") uid_logger_dubug("--uri_exec: .....res is #{res}")
JSON.parse(res) JSON.parse(res)
rescue Exception => e rescue Exception => e
uid_logger_error("--uri_exec: exception #{e.message}") uid_logger_error("--uri_exec: exception #{e.message}")
@ -367,10 +367,10 @@ class ApplicationController < ActionController::Base
# 处理返回非0就报错的请求 # 处理返回非0就报错的请求
def interface_post(uri, params, status, message) def interface_post(uri, params, status, message)
begin begin
uid_logger("--uri_exec: params is #{params}, url is #{uri}") uid_logger_dubug("--uri_exec: params is #{params}, url is #{uri}")
uri = URI.parse(URI.encode(uri.strip)) uri = URI.parse(URI.encode(uri.strip))
res = Net::HTTP.post_form(uri, params).body res = Net::HTTP.post_form(uri, params).body
logger.info("--uri_exec: .....res is #{res}") uid_logger_dubug("--uri_exec: .....res is #{res}")
res = JSON.parse(res) res = JSON.parse(res)
if (res && res['code'] != 0) if (res && res['code'] != 0)
tip_exception(status, message) tip_exception(status, message)

@ -9,6 +9,12 @@ module LoggerHelper
Rails.logger.info("##:#{current_user.try(:id)} --#{message}") Rails.logger.info("##:#{current_user.try(:id)} --#{message}")
end end
# debug日志
def uid_logger_dubug(message)
Rails.logger.info("##dubug-#{current_user.try(:id)} --#{message}")
end
# 以用户id开始的日志定义 # 以用户id开始的日志定义
def uid_logger_error(message) def uid_logger_error(message)
Rails.logger.error("##:#{current_user.try(:id)} --#{message}") Rails.logger.error("##:#{current_user.try(:id)} --#{message}")

@ -11,7 +11,7 @@ class GamesController < ApplicationController
include ApplicationHelper include ApplicationHelper
def show def show
uid_logger("--games show start") uid_logger_dubug("--games show start")
# 防止评测中途ajaxE被取消;3改成0是为了处理首次进入下一关的问题 # 防止评测中途ajaxE被取消;3改成0是为了处理首次进入下一关的问题
update_game_parameter(@game) update_game_parameter(@game)
@ -439,7 +439,7 @@ class GamesController < ApplicationController
path = params[:path] || path path = params[:path] || path
status = params[:status].to_i status = params[:status].to_i
path = path.try(:strip) path = path.try(:strip)
uid_logger("--rep_content: path is #{path}") uid_logger_dubug("--rep_content: path is #{path}")
begin begin
@content = git_fle_content(@myshixun.repo_path, path) || "" @content = git_fle_content(@myshixun.repo_path, path) || ""
rescue Exception => e rescue Exception => e
@ -455,7 +455,7 @@ class GamesController < ApplicationController
# 监测版本库HEAD是否存在不存在则取最新的HEAD # 监测版本库HEAD是否存在不存在则取最新的HEAD
uri = "#{shixun_tomcat}/bridge/game/check" uri = "#{shixun_tomcat}/bridge/game/check"
res = uri_post uri, rep_params res = uri_post uri, rep_params
uid_logger("repo_content to bridge: res is #{res}") uid_logger_dubug("repo_content to bridge: res is #{res}")
# res值0 表示正常;-1表示有错误-2表示代码版本库没了 # res值0 表示正常;-1表示有错误-2表示代码版本库没了
# #
if status == 0 && res if status == 0 && res
@ -507,11 +507,10 @@ class GamesController < ApplicationController
else else
{updated_at: Time.now} {updated_at: Time.now}
end end
logger.info("#############myshixuns_update: ##{myshixuns_update}")
@myshixun.update_attributes!(myshixuns_update) @myshixun.update_attributes!(myshixuns_update)
gitUrl = repo_ip_url @myshixun.repo_path gitUrl = repo_ip_url @myshixun.repo_path
logger.info("#############giturl: ##{gitUrl}") uid_logger_dubug("#############giturl: ##{gitUrl}")
gitUrl = Base64.urlsafe_encode64(gitUrl) gitUrl = Base64.urlsafe_encode64(gitUrl)
shixun_tomcat = edu_setting('cloud_bridge') shixun_tomcat = edu_setting('cloud_bridge')
@ -537,7 +536,7 @@ class GamesController < ApplicationController
testSet << test_cases testSet << test_cases
end end
logger.info("##############testSet: #{testSet}") uid_logger_dubug("##############testSet: #{testSet}")
testCases = Base64.urlsafe_encode64(testSet.to_json) unless testSet.blank? testCases = Base64.urlsafe_encode64(testSet.to_json) unless testSet.blank?
# 评测类型: 012 用于webssh的评测 3用于vnc # 评测类型: 012 用于webssh的评测 3用于vnc
@ -560,11 +559,11 @@ class GamesController < ApplicationController
# 私密仓库的设置 # 私密仓库的设置
secret_rep = @shixun.shixun_secret_repository secret_rep = @shixun.shixun_secret_repository
logger.info("############secret_rep: #{secret_rep}") uid_logger_dubug("############secret_rep: #{secret_rep}")
if secret_rep&.repo_name if secret_rep&.repo_name
secretGitUrl = repo_ip_url secret_rep.repo_path secretGitUrl = repo_ip_url secret_rep.repo_path
br_params.merge!({secretGitUrl: Base64.urlsafe_encode64(secretGitUrl), secretDir: secret_rep.secret_dir_path}) br_params.merge!({secretGitUrl: Base64.urlsafe_encode64(secretGitUrl), secretDir: secret_rep.secret_dir_path})
logger.info("#######br_params:#{br_params}") uid_logger_dubug("#######br_params:#{br_params}")
end end
# 中间层交互 # 中间层交互
@ -580,7 +579,6 @@ class GamesController < ApplicationController
# 选择题评测 # 选择题评测
def choose_build def choose_build
Rails.logger.error("#################{params}")
# 选择题如果通关了,则不让再评测 # 选择题如果通关了,则不让再评测
if @game.status == 2 if @game.status == 2
raise Educoder::TipException.new("您已通过该关卡") raise Educoder::TipException.new("您已通过该关卡")
@ -623,7 +621,7 @@ class GamesController < ApplicationController
end end
# 批量插入评测结果 # 批量插入评测结果
uid_logger("#------------chooice score: #{score}") uid_logger_dubug("#------------chooice score: #{score}")
sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str
ActiveRecord::Base.connection.execute sql ActiveRecord::Base.connection.execute sql
@ -683,10 +681,10 @@ class GamesController < ApplicationController
resubmit_identifier = @game.resubmit_identifier resubmit_identifier = @game.resubmit_identifier
# 如果没有超时并且正在评测中 # 如果没有超时并且正在评测中
# 判断评测中的状态有两种1、如果之前没有通关的只需判断status为1即可如果通过关则判断game的resubmit_identifier是否更新 # 判断评测中的状态有两种1、如果之前没有通关的只需判断status为1即可如果通过关则判断game的resubmit_identifier是否更新
uid_logger("################game_status: #{@game.status}") uid_logger_dubug("################game_status: #{@game.status}")
uid_logger("################params[:resubmit]: #{params[:resubmit]}") uid_logger_dubug("################params[:resubmit]: #{params[:resubmit]}")
uid_logger("################resubmit_identifier: #{resubmit_identifier}") uid_logger_dubug("################resubmit_identifier: #{resubmit_identifier}")
uid_logger("################time_out: #{params[:time_out]}") uid_logger_dubug("################time_out: #{params[:time_out]}")
sec_key = params[:sec_key] sec_key = params[:sec_key]
if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? && if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? &&
(params[:resubmit] != resubmit_identifier))) (params[:resubmit] != resubmit_identifier)))
@ -696,7 +694,7 @@ class GamesController < ApplicationController
render :json => { running_code_status: running_code_status, running_code_message: running_code_message } render :json => { running_code_status: running_code_status, running_code_message: running_code_message }
end end
uid_logger("##### resubmit_identifier is #{resubmit_identifier}") uid_logger_dubug("##### resubmit_identifier is #{resubmit_identifier}")
port = params[:port] port = params[:port]
score = 0 score = 0
experience = 0 experience = 0
@ -745,7 +743,7 @@ class GamesController < ApplicationController
end end
end end
uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") uid_logger_dubug("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
# 记录前端总耗时 # 记录前端总耗时
record_consume_time = e_record.try(:pod_execute) record_consume_time = e_record.try(:pod_execute)
max_mem = e_record.try(:max_mem) max_mem = e_record.try(:max_mem)
@ -791,7 +789,7 @@ class GamesController < ApplicationController
begin begin
shixun_tomcat = edu_setting('cloud_bridge') shixun_tomcat = edu_setting('cloud_bridge')
uri = "#{shixun_tomcat}/bridge/webssh/delete" uri = "#{shixun_tomcat}/bridge/webssh/delete"
Rails.logger.info("#{current_user} => cloese_webssh digest is #{digest}") uid_logger_dubug("#{current_user} => cloese_webssh digest is #{digest}")
params = {:tpiID => myshixun_id, :digestKey => digest_key, :identifier => @game.identifier} params = {:tpiID => myshixun_id, :digestKey => digest_key, :identifier => @game.identifier}
res = uri_post uri, params res = uri_post uri, params
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
@ -830,7 +828,7 @@ class GamesController < ApplicationController
@allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户 @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户
if max_query_index > 0 if max_query_index > 0
uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") uid_logger_dubug("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}")
@qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time, o.ts_mem, @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time, o.ts_mem,
o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c, o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c,
test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index} test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index}

@ -90,7 +90,7 @@ class MyshixunsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
t1 = Time.now t1 = Time.now
Rails.logger.info("@@@222222#{params[:jsonTestDetails]}") uid_logger_dubug("@@@222222#{params[:jsonTestDetails]}")
jsonTestDetails = JSON.parse(params[:jsonTestDetails]) jsonTestDetails = JSON.parse(params[:jsonTestDetails])
timeCost = JSON.parse(params[:timeCost]) timeCost = JSON.parse(params[:timeCost])
brige_end_time = Time.parse(timeCost['evaluateEnd']) if timeCost['evaluateEnd'].present? brige_end_time = Time.parse(timeCost['evaluateEnd']) if timeCost['evaluateEnd'].present?
@ -99,7 +99,7 @@ class MyshixunsController < ApplicationController
game_id = jsonTestDetails['buildID'] game_id = jsonTestDetails['buildID']
sec_key = jsonTestDetails['sec_key'] sec_key = jsonTestDetails['sec_key']
logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") uid_logger_dubug("training_task_status start-#{game_id}-1#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
resubmit = jsonTestDetails['resubmit'] resubmit = jsonTestDetails['resubmit']
outPut = tran_base64_decode64(jsonTestDetails['outPut']) outPut = tran_base64_decode64(jsonTestDetails['outPut'])
@ -116,17 +116,14 @@ class MyshixunsController < ApplicationController
pics = params[:tpiRepoPath] pics = params[:tpiRepoPath]
game.update_column(:picture_path, pics) game.update_column(:picture_path, pics)
end end
logger.info("training_task_status start#2**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
max_query_index = game.outputs ? (game.outputs.first.try(:query_index).to_i + 1) : 1 max_query_index = game.outputs ? (game.outputs.first.try(:query_index).to_i + 1) : 1
test_set_score = 0 test_set_score = 0
unless jenkins_testsets.blank? unless jenkins_testsets.blank?
jenkins_testsets.each_with_index do |j_test_set, i| jenkins_testsets.each_with_index do |j_test_set, i|
logger.info("j_test_set: ############## #{j_test_set}")
actual_output = tran_base64_decode64(j_test_set['output']) actual_output = tran_base64_decode64(j_test_set['output'])
#ts_time += j_test_set['testSetTime'].to_i #ts_time += j_test_set['testSetTime'].to_i
# is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public)
logger.info "actual_output:################################################# #{actual_output}"
ts_time = format("%.2f", j_test_set['testSetTime'].to_f/1000000000).to_f if j_test_set['testSetTime'] ts_time = format("%.2f", j_test_set['testSetTime'].to_f/1000000000).to_f if j_test_set['testSetTime']
ts_mem = format("%.2f", j_test_set['testSetMem'].to_f/1024/1024).to_f if j_test_set['testSetMem'] ts_mem = format("%.2f", j_test_set['testSetMem'].to_f/1024/1024).to_f if j_test_set['testSetMem']
@ -139,15 +136,12 @@ class MyshixunsController < ApplicationController
end end
end end
end end
uid_logger("#############status: #{status}")
record = EvaluateRecord.where(:identifier => sec_key).first record = EvaluateRecord.where(:identifier => sec_key).first
logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比. answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比.
# answer_deduction是查看答案的扣分比例 # answer_deduction是查看答案的扣分比例
# status0表示评测成功 # status0表示评测成功
if status == "0" if status == "0"
if resubmit.present? if resubmit.present?
uid_logger("#############resubmitdaiao: #{resubmit}")
game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit) game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit)
challenge.path.split("").each do |path| challenge.path.split("").each do |path|
game_passed_code(path.try(:strip), myshixun, game_id) game_passed_code(path.try(:strip), myshixun, game_id)
@ -205,7 +199,6 @@ class MyshixunsController < ApplicationController
:pod_execute => timeCost['execute'], :test_cases => test_cases_time, :pod_execute => timeCost['execute'], :test_cases => test_cases_time,
:brige => timeCost['evaluateAllTime'], :return_back => return_back_time) :brige => timeCost['evaluateAllTime'], :return_back => return_back_time)
end end
uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
sucess_status sucess_status
# rescue Exception => e # rescue Exception => e
# tip_exception(e.message) # tip_exception(e.message)
@ -265,7 +258,7 @@ class MyshixunsController < ApplicationController
@sec_key = generate_identifier(EvaluateRecord, 12) @sec_key = generate_identifier(EvaluateRecord, 12)
record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id, record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id,
:identifier => @sec_key, :exec_time => exec_time) :identifier => @sec_key, :exec_time => exec_time)
uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") uid_logger_dubug("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
end end
# 隐藏代码文件 和 VNC的都不需要走版本库 # 隐藏代码文件 和 VNC的都不需要走版本库
unless @hide_code || @myshixun.shixun&.vnc_evaluate unless @hide_code || @myshixun.shixun&.vnc_evaluate
@ -276,8 +269,8 @@ class MyshixunsController < ApplicationController
else else
params[:content] params[:content]
end end
Rails.logger.info("###11222333####{content}") uid_logger_dubug("###11222333####{content}")
Rails.logger.info("###222333####{last_content}") uid_logger_dubug("###222333####{last_content}")
if content != last_content if content != last_content
@content_modified = 1 @content_modified = 1
@ -285,8 +278,8 @@ class MyshixunsController < ApplicationController
author_name = current_user.real_name author_name = current_user.real_name
author_email = current_user.git_mail author_email = current_user.git_mail
message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted"
uid_logger("112233#{author_name}") uid_logger_dubug("112233#{author_name}")
uid_logger("112233#{author_email}") uid_logger_dubug("112233#{author_email}")
@content = GitService.update_file(repo_path: @repo_path, @content = GitService.update_file(repo_path: @repo_path,
file_path: path, file_path: path,
message: message, message: message,

Loading…
Cancel
Save