games添加事务回滚处理

This commit is contained in:
huang 2017-03-30 17:17:34 +08:00
parent 9d770bfcb9
commit 67e4a5982a
1 changed files with 21 additions and 14 deletions

View File

@ -95,22 +95,29 @@ class GamesController < ApplicationController
gitUrl = Base64.encode64(gitUrl) gitUrl = Base64.encode64(gitUrl)
taskId = params[:id] taskId = params[:id]
jobName = "myshixun_#{@myshixun.id}" jobName = "myshixun_#{@myshixun.id}"
@game.update_attribute(:status, 1) ActiveRecord::Base.transaction do
testCode = {} @game.update_attributes!(:status => 1)
test_sets = game_challenge.test_sets testCode = {}
unless test_sets.blank? test_sets = game_challenge.test_sets
test_sets.each_with_index do |test_set, index| unless test_sets.blank?
testCode.store("testCode_#{index}",test_set.try(:output)) test_sets.each_with_index do |test_set, index|
testCode.store("testCode_#{index}",test_set.try(:output))
end
end end
testCode = testCode.to_json
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
step = game_challenge.try(:position)
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}", :testCode => "#{testCode}"}
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJob")
res = uri_exec uri, params
if (res && res['code'] != 0)
raise("Build job failed")
end
render :json => {data:"success"}
end end
testCode = testCode.to_json rescue
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] raise ActiveRecord::Rollback
step = game_challenge.try(:position) redirect_to myshixun_game_path(@game, :myshixun_id => @myshixun)
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}", :testCode => "#{testCode}"}
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJob")
res = uri_exec uri, params
render :json => {data:"success"}
end end
def game_status def game_status