rake 任务异常跳过

This commit is contained in:
siteen 2016-12-14 13:32:25 +08:00
parent 5f56edda15
commit be1fc144da
1 changed files with 25 additions and 19 deletions

View File

@ -3,28 +3,36 @@ namespace :gitlab do
task :sync_data => :environment do
s = Trustie::Gitlab::Sync.new
g = Gitlab.client
begin
projects = Project.where("gpid is not null and status=?", 1)
projects.each do |project|
# sync members and roles
projects = Project.where("gpid is not null and status=?", 1)
projects.each do |project|
# sync members and roles
begin
if project.members.count != g.team_members(project.gpid).count
DataException.create(:message => "project's members is not true", :container_id => project.id, :container_type => "Project")
project.members.each do |m|
gid = m.user.gid
if gid.nil?
gid = s.sync_user(m.user).id
begin
gid = m.user.gid
if gid.nil?
gid = s.sync_user(m.user).id
end
access_level = m.roles[0].position == 3 ? 40 : (m.roles[0].position == 4 ? 30 : 20)
# sync project's members
g.add_team_member(project.gpid, gid, access_level)
# sync members' roles
g.edit_team_member(project.gpid, gid, access_level)
rescue Exception => e
DataException.create(:message => e.message, :container_id => project.id, :container_type => "Project")
puts e
end
access_level = m.roles[0].position == 3 ? 40 : (m.roles[0].position == 4 ? 30 : 20)
# sync project's members
g.add_team_member(project.gpid, gid, access_level)
# sync members' roles
g.edit_team_member(project.gpid, gid, access_level)
end
end
rescue Exception => e
puts e
end
end
users = User.where("gid is not null and status =?", 1)
users.each do |user|
users = User.where("gid is not null and status =?", 1)
users.each do |user|
begin
# sync username
g.edit_user(user.gid, :username => user.login) if user.login != g.user(user.gid).try(:username)
@ -34,11 +42,9 @@ namespace :gitlab do
# sync password
options = {:encrypted_password=> user.hashed_password, :password_salt=> user.salt}
g.put("/users/ext/#{user.gid}", :body => options)
rescue Exception => e
puts e
end
rescue Exception => e
DataException.create(:message => e.message)
puts e
end
end
end