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,7 +95,8 @@ 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
@game.update_attributes!(:status => 1)
testCode = {} testCode = {}
test_sets = game_challenge.test_sets test_sets = game_challenge.test_sets
unless test_sets.blank? unless test_sets.blank?
@ -109,8 +110,14 @@ class GamesController < ApplicationController
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}", :testCode => "#{testCode}"} params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}", :testCode => "#{testCode}"}
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJob") uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJob")
res = uri_exec uri, params res = uri_exec uri, params
if (res && res['code'] != 0)
raise("Build job failed")
end
render :json => {data:"success"} render :json => {data:"success"}
end
rescue
raise ActiveRecord::Rollback
redirect_to myshixun_game_path(@game, :myshixun_id => @myshixun)
end end
def game_status def game_status