Fixed race condtion while importing history types for the first time.

This commit is contained in:
Thorsten Eckel 2016-11-29 12:04:09 +01:00
parent 0757228257
commit e72d6c3fd4

View file

@ -1,9 +1,11 @@
# rubocop:disable Style/ClassVars
module Import module Import
module OTRS module OTRS
class History class History
def initialize(history) def initialize(history)
init_callback(history) init_callback(history)
ensure_history_attribute
add add
end end
@ -16,6 +18,18 @@ module Import
def add def add
::History.add(@history_attributes) ::History.add(@history_attributes)
end end
# make sure that no other thread is importing just the same
# history attribute which causes a ActiveRecord::RecordNotUnique
# exception we (currently) can't handle otherwise
def ensure_history_attribute
history_attribute = @history_attributes[:history_attribute]
return if !history_attribute
@@created_history_attributes ||= {}
return if @@created_history_attributes[history_attribute]
@@created_history_attributes[history_attribute] = true
::History.attribute_lookup(history_attribute)
end
end end
end end
end end