dev_shixuns
cxt 6 years ago
parent 8ba070106d
commit 6c8401ab04

@ -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?
@ -64,7 +78,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

Loading…
Cancel
Save