Refactored history creation and made it thread safe.

This commit is contained in:
Thorsten Eckel 2015-07-24 12:06:46 +02:00
parent 899d56434a
commit 29235acd90

View file

@ -686,9 +686,10 @@ module Import::OTRS
#puts "HS: #{record['History'].inspect}"
record['History'].each { |history|
begin
if history['HistoryType'] == 'NewTicket'
#puts "HS.add( #{history.inspect} )"
res = History.add(
History.add(
id: history['HistoryID'],
o_id: history['TicketID'],
history_type: 'created',
@ -696,9 +697,7 @@ module Import::OTRS
created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
#puts "res #{res.inspect}"
end
if history['HistoryType'] == 'StateUpdate'
elsif history['HistoryType'] == 'StateUpdate'
data = history['Name']
# "%%new%%open%%"
from = nil
@ -728,8 +727,7 @@ module Import::OTRS
created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
end
if history['HistoryType'] == 'Move'
elsif history['HistoryType'] == 'Move'
data = history['Name']
# "%%Queue1%%5%%Postmaster%%1"
from = nil
@ -753,8 +751,7 @@ module Import::OTRS
created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
end
if history['HistoryType'] == 'PriorityUpdate'
elsif history['HistoryType'] == 'PriorityUpdate'
data = history['Name']
# "%%3 normal%%3%%5 very high%%5"
from = nil
@ -778,11 +775,7 @@ module Import::OTRS
created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
end
next if !history['ArticleID']
next if history['ArticleID'] == 0
elsif history['ArticleID'] && !history['ArticleID'].zero?
History.add(
id: history['HistoryID'],
o_id: history['ArticleID'],
@ -793,6 +786,12 @@ module Import::OTRS
created_at: history['CreateTime'],
created_by_id: history['CreateBy']
)
end
rescue ActiveRecord::RecordNotUnique
log "Ticket #{ticket_new[:id]} (history #{history['HistoryID']}) is handled by another thead, skipping."
next
end
}
}
end