Removed locks workaround.

This commit is contained in:
Thorsten Eckel 2015-07-24 12:00:03 +02:00
parent 12cf0122ca
commit 6ddfd595d6

View file

@ -378,7 +378,6 @@ module Import::OTRS
thread_count = 8 thread_count = 8
threads = {} threads = {}
steps = 20 steps = 20
locks = { User: {} }
(1..thread_count).each {|thread| (1..thread_count).each {|thread|
threads[thread] = Thread.new { threads[thread] = Thread.new {
@ -399,7 +398,7 @@ module Import::OTRS
log "... thread# #{thread}, no more work." log "... thread# #{thread}, no more work."
break break
end end
_ticket_result(records, locks, thread) _ticket_result(records, thread)
Thread.current[:loop_count] += 1 Thread.current[:loop_count] += 1
end end
@ -465,7 +464,6 @@ module Import::OTRS
count = 0 count = 0
run = true run = true
steps = 20 steps = 20
locks = { User: {} }
while run while run
count += steps count += steps
log 'loading... diff ...' log 'loading... diff ...'
@ -479,12 +477,12 @@ module Import::OTRS
run = false run = false
next next
end end
_ticket_result(records, locks) _ticket_result(records)
end end
end end
def self._ticket_result(result, locks, _thread = '-') def self._ticket_result(result, _thread = '-')
map = { map = {
Ticket: { Ticket: {
Changed: :updated_at, Changed: :updated_at,
@ -588,7 +586,7 @@ module Import::OTRS
# lookup customers to create first # lookup customers to create first
record['Articles'].each { |article| record['Articles'].each { |article|
_article_based_customers(article, locks) _article_based_customers(article)
} }
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@ -1270,7 +1268,7 @@ module Import::OTRS
end end
# create customers for article # create customers for article
def self._article_based_customers(article, locks) def self._article_based_customers(article)
# create customer/sender if needed # create customer/sender if needed
return if article['sender'] != 'customer' return if article['sender'] != 'customer'
@ -1287,15 +1285,6 @@ module Import::OTRS
end end
end end
# create article user if not exists
while locks[:User][ email ]
log "user #{email} is locked"
sleep 1
end
# lock user
locks[:User][ email ] = true
user = User.where( email: email ).first user = User.where( email: email ).first
if !user if !user
user = User.where( login: email ).first user = User.where( login: email ).first
@ -1326,9 +1315,6 @@ module Import::OTRS
end end
article['created_by_id'] = user.id article['created_by_id'] = user.id
# unlock user
locks[:User][ email ] = false
true true
end end