|
|
@ -1,4 +1,17 @@
|
|
|
|
class CreateShixunStudentWorks < ActiveRecord::Migration
|
|
|
|
class CreateShixunStudentWorks < ActiveRecord::Migration
|
|
|
|
|
|
|
|
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def down_generate_identifier type
|
|
|
|
|
|
|
|
if type == "game"
|
|
|
|
|
|
|
|
code = DCODES.sample(12).join
|
|
|
|
|
|
|
|
return down_generate_identifier(type) if Game.where(identifier: code).present?
|
|
|
|
|
|
|
|
elsif type == "myshixun"
|
|
|
|
|
|
|
|
code = DCODES.sample(10).join
|
|
|
|
|
|
|
|
return down_generate_identifier(type) if Myshixun.where(identifier: code).present?
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
code
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def up
|
|
|
|
def up
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
begin
|
|
|
|
begin
|
|
|
@ -20,6 +33,7 @@ class CreateShixunStudentWorks < ActiveRecord::Migration
|
|
|
|
end
|
|
|
|
end
|
|
|
|
gshixun = g.fork(shixun.gpid, user.gid)
|
|
|
|
gshixun = g.fork(shixun.gpid, user.gid)
|
|
|
|
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
|
|
|
|
shixun_tomcat = Redmine::Configuration['shixun_tomcat']
|
|
|
|
|
|
|
|
|
|
|
|
code = down_generate_identifier("myshixun")
|
|
|
|
code = down_generate_identifier("myshixun")
|
|
|
|
# 一般通过默认分支是否存在来判断一个项目是否fork成功
|
|
|
|
# 一般通过默认分支是否存在来判断一个项目是否fork成功
|
|
|
|
if gshixun.try(:id).present?
|
|
|
|
if gshixun.try(:id).present?
|
|
|
@ -33,11 +47,15 @@ class CreateShixunStudentWorks < ActiveRecord::Migration
|
|
|
|
:onclick_time => Time.now, :gpid => gshixun.id,
|
|
|
|
:onclick_time => Time.now, :gpid => gshixun.id,
|
|
|
|
:git_url => gshixun.try(:path_with_namespace), :commit_id => commit_id)
|
|
|
|
:git_url => gshixun.try(:path_with_namespace), :commit_id => commit_id)
|
|
|
|
|
|
|
|
|
|
|
|
rep_url = Base64.urlsafe_encode64(gitlab_url shixun) # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改
|
|
|
|
url = "#{Redmine::Configuration['gitlab_address_ip']}/#{g.project(shixun.try(:gpid)).try(:path_with_namespace)}.git"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rep_url = Base64.urlsafe_encode64(url) # 注意:educoder为默认给实训创建版本库的用户,如果换成别的用户,名字要相应的修改
|
|
|
|
uri = "#{shixun_tomcat}/bridge/game/openGameInstance"
|
|
|
|
uri = "#{shixun_tomcat}/bridge/game/openGameInstance"
|
|
|
|
params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)}
|
|
|
|
params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: gshixun.try(:name)}
|
|
|
|
logger.info("openGameInstance params is #{params}")
|
|
|
|
logger.info("openGameInstance params is #{params}")
|
|
|
|
res = uri_exec uri, params
|
|
|
|
uri = URI.parse(URI.encode(uri.strip))
|
|
|
|
|
|
|
|
res = Net::HTTP.post_form(uri, params).body
|
|
|
|
|
|
|
|
res = JSON.parse(res)
|
|
|
|
if (res && res['code'].to_i != 0)
|
|
|
|
if (res && res['code'].to_i != 0)
|
|
|
|
raise("实训云平台繁忙(繁忙等级:83)")
|
|
|
|
raise("实训云平台繁忙(繁忙等级:83)")
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -64,7 +82,7 @@ class CreateShixunStudentWorks < ActiveRecord::Migration
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
puts ("###failed to exec shixun: current task id is #{e}")
|
|
|
|
puts ("###failed to exec shixun: current task id is #{e}")
|
|
|
|
g.delete_project(gshixun.id) if gshixun.try(:id).present?
|
|
|
|
# g.delete_project(gshixun.id) if gshixun.try(:id).present?
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|