From 9c35010dfe883e85fd32e6944f16d6e70c14c8ff Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 16 Jan 2020 14:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=B7=E5=90=88=E4=BA=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 +++- app/controllers/myshixuns_controller.rb | 5 +++++ app/models/game.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index fcdd81953..b37b925f9 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -749,6 +749,8 @@ class GamesController < ApplicationController # 针对web类型的实训 web_route = game_challenge.try(:web_route) + server_url = @game.get_server_url if web_route.present? + mirror_name = @shixun.mirror_name e_record = EvaluateRecord.where(:identifier => sec_key).first @@ -776,7 +778,7 @@ class GamesController < ApplicationController @base_date = {grade: grade, gold: score, experience: experience, status: game_status, had_done: had_done, position: game_challenge.position, port: port, record_consume_time: record_consume_time, mirror_name: mirror_name, picture: picture, web_route: web_route, star: @game.star, - next_game: next_game, prev_game: prev_game, max_mem: max_mem} + next_game: next_game, prev_game: prev_game, max_mem: max_mem, server_url: server_url} end # 记录实训花费的时间 diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 350ee581f..67a6cabd9 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -99,6 +99,7 @@ class MyshixunsController < ApplicationController status = jsonTestDetails['status'] game_id = jsonTestDetails['buildID'] sec_key = jsonTestDetails['sec_key'] + server_url = jsonTestDetails['showServer'] uid_logger_dubug("training_task_status start-#{game_id}-1#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] @@ -117,6 +118,10 @@ class MyshixunsController < ApplicationController pics = params[:tpiRepoPath] game.update_column(:picture_path, pics) end + # 如果启动了服务,则存在redis中,供前端访问 + if server_url.present? + game.set_server_key(server_url) + end max_query_index = game.outputs ? (game.outputs.first.try(:query_index).to_i + 1) : 1 test_set_score = 0 unless jenkins_testsets.blank? diff --git a/app/models/game.rb b/app/models/game.rb index 062ad15cc..144dbced2 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -29,6 +29,19 @@ class Game < ApplicationRecord validates :identifier, uniqueness: true + # 服务器uri+port的redis的key + def server_key + "game_server_url_#{id}" + end + + def set_server_key(server_url) + Rails.cache.write("#{server_key}", server_url, expires_in: 5.minute) + end + + def get_server_url + Rails.cache.read(server_key) + end + # 根据得分比例来算实际得分(试卷、实训作业) def real_score score ((final_score < 0 ? 0 : final_score).to_f / challenge.score) * score