实训代码更新异步处理及流程优化
This commit is contained in:
parent
1ba3d74364
commit
42cfced635
|
|
@ -16,62 +16,32 @@ class GamesController < ApplicationController
|
|||
# 同步完成后,需要更新myshixun的commit_id为实训的commit最新值
|
||||
# --------------------------
|
||||
# 新思路,有冲突则则重置,没有冲突直接pull
|
||||
# identifier为password---
|
||||
# --------------------------
|
||||
def sync_codes
|
||||
g = Gitlab.client
|
||||
myshixun_user_login = User.where(:id => @myshixun.user_id).first.try(:login)
|
||||
myshixun_rep_identifier = Repository.where(:myshixun_id => @myshixun.id, :type => "Repository::Gitlab").first.try(:identifier)
|
||||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
myshixun_domain = Redmine::Configuration['myshixun_domain']
|
||||
gitlab_myshixun_url = git_myshixun_url(@myshixun, @myshixun.try(:user_id))
|
||||
shixun = @myshixun.shixun
|
||||
gitlab_shixun_url = git_shixun_url(shixun, (shixun.try(:fork_from).blank? ? "educoder" : "eduforge"))
|
||||
if RUBY_PLATFORM =~ /w32/
|
||||
path = "c:/test/"
|
||||
else
|
||||
path = "/home/pdl/myshixun_shell"
|
||||
begin
|
||||
git_myshixun_url = git_myshixun_url_ip(@myshixun, @myshixun.try(:user_id))
|
||||
login = @myshixun.shixun.try(:git_login)
|
||||
git_shixun_url = git_shixun_url_ip(@myshixun.shixun, login)
|
||||
params = {tpmID: "#{shixun.id}", :tpiGitURL => "#{git_myshixun_url}", :tpmGitURL => "#{git_shixun_url}", :commitId => "#{@myshixun.commit_id}", :identifier => "xinhu1ji2qu3"}
|
||||
uri = "#{shixun_tomcat}/bridge/game/resetTpmRepository"
|
||||
res = uri_exec uri, params
|
||||
if (res && res['code'] != 0)
|
||||
@message = "实训云平台繁忙(繁忙等级:95)"
|
||||
raise("实训云平台繁忙(繁忙等级:95)")
|
||||
end
|
||||
shixun_new_commit = g.commits(@myshixun.shixun.try(:gpid)).first.try(:id)
|
||||
@myshixun.update_column(:commit_id, shixun_new_commit)
|
||||
respond_to do |format|
|
||||
format.js{ redirect_to myshixun_game_path( @game, :myshixun_id => @myshixun)}
|
||||
end
|
||||
rescue Exception => e
|
||||
logger.error(e)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
script = "cd #{path}
|
||||
git clone #{gitlab_address.to_s+'/'+myshixun_user_login+'/'+ myshixun_rep_identifier}.git
|
||||
cd #{myshixun_rep_identifier}/
|
||||
git remote set-url origin https://#{shixun.fork_from.blank? ? "educoder" : "eduforge"}:xinhu1ji2qu3@#{myshixun_domain}/#{myshixun_user_login}/#{myshixun_rep_identifier}.git
|
||||
git remote add remote_origin #{gitlab_shixun_url}
|
||||
#git pull
|
||||
git pull remote_origin master
|
||||
if [ $? -eq 0 ];then
|
||||
echo -e 'git pull succssed'
|
||||
else
|
||||
git reset --hard #{@myshixun.commit_id}
|
||||
git pull remote_origin master
|
||||
if [ $? -eq 0 ];then
|
||||
echo -e 'git reset and pull succssed'
|
||||
else
|
||||
echo -e 'git reset and pull failed'
|
||||
fi
|
||||
fi
|
||||
git push -f origin master
|
||||
if [ $? -eq 0 ];then
|
||||
echo -e 'git push succssed'
|
||||
else
|
||||
echo -e 'git push failed'
|
||||
fi
|
||||
cd ../
|
||||
rm -rf #{myshixun_rep_identifier}/"
|
||||
aFile =File.new(File.join("#{path}","#{@myshixun.identifier}.sh"), "w+")
|
||||
if aFile
|
||||
aFile.syswrite(script)
|
||||
else
|
||||
logger.error "Unable to open file!"
|
||||
end
|
||||
system("sh #{path}/#{@myshixun.identifier}.sh")
|
||||
# stdin, stdout, stderr = Open3.popen3("sh #{path}/#{@myshixun.identifier}.sh")
|
||||
shixun_new_commit = g.commits(@myshixun.shixun.try(:gpid)).first.try(:id)
|
||||
@myshixun.update_column(:commit_id, shixun_new_commit)
|
||||
sleep(2) # g
|
||||
respond_to do |format|
|
||||
format.js{ redirect_to myshixun_game_path( @game, :myshixun_id => @myshixun)}
|
||||
end
|
||||
# render :json => {:status => 200}
|
||||
|
||||
end
|
||||
|
||||
def index
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
# 90: 更新公共测试用例失败,返回code非0;91:实训有改动,评测的时候初始化数据,返回数据code非0;92:webssh开启失败,接口getConnectInfo返回code值非0
|
||||
# 93: 实训断开连接失败,接口deleteSSH返回code值非0
|
||||
# 94: 获取评测等待时间失败,接口getWaitingTime返回code值为非0
|
||||
# 95:代码重置失败
|
||||
# 116:challenge创建关卡的时候返回结果错误
|
||||
#
|
||||
class Shixun < ActiveRecord::Base
|
||||
|
|
@ -29,6 +30,13 @@ class Shixun < ActiveRecord::Base
|
|||
scope :visible, lambda{where(status: [2,3])}
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
# 实训的版本库创建者为"educoder" 和"eduforge"
|
||||
# "educoder"为原创,"eduforge"为复制的时候用户
|
||||
def git_login
|
||||
shixun.fork_from.blank? ? "educoder" : "eduforge"
|
||||
end
|
||||
|
||||
# 获取特定格式的实训测试用例
|
||||
# params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}",
|
||||
# :challengeProgramName => "#{@challenge.exec_path}",
|
||||
|
|
|
|||
Loading…
Reference in New Issue