diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 15758b7fe..f40fefe13 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -25,7 +25,8 @@ class ChallengesController < ApplicationController @challenge.shixun = @shixun @challenge.user = User.current ActiveRecord::Base.transaction do - if @challenge.save + begin + @challenge.save! if params[:sample][:input].length > 0 params[:sample][:input].each_with_index do |value, index| unless (value == params[:sample][:output][index] && value.blank?) @@ -43,21 +44,34 @@ class ChallengesController < ApplicationController ChallengeTag.create(:name => input, :challenge_id => @challenge.id) end end - # 向jenkins端发送请求,构建pipeline片段 - params = {:shixunType => "#{@challenge.evaluation_way.to_i}", :filePath => "#{@challenge.path}", :step => "#{@challenge.position}"} - uri = URI("#{jenkins_shixuns}/jenkins-exec/api/generateScriptPerChallenge") - res = uri_exec uri, params + # 向jenkins端发送请求,构建pipeline片段,实时返回结果 + begin + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + params = {:shixunType => "#{@challenge.evaluation_way.to_i}", :filePath => "#{@challenge.path}", :step => "#{@challenge.position}", :challengeId => "#{@challenge.id}"} + uri = URI("#{jenkins_shixuns}/jenkins-exec/api/generateScriptPerChallenge") + res = uri_exec uri, params + if res.blank? + raise("jenkins服务器异常") + end + rescue + raise("jenkins服务器异常") + end respond_to do |format| format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '创建成功!'} end - else - respond_to do |format| - format.html { render :action => 'new' } - end + rescue Exception => e + flash[:error] = "#{e.message}" + redirect_to new_shixun_challenge_path(:shixun_id => @shixun.id) + raise ActiveRecord::Rollback end end end + # 处理新建challenge返回的pipeline片段 + def fragment_from_jenkins + + end + def index # 顶部导航 @challenges = @shixun.challenges.order("position desc")