Improved logging.
This commit is contained in:
parent
08f2c924ef
commit
cf3e6274d0
5 changed files with 40 additions and 44 deletions
|
@ -207,8 +207,6 @@ Style/RedundantSelf:
|
|||
Enabled: false
|
||||
Style/Next:
|
||||
Enabled: false
|
||||
Rails/Output:
|
||||
Enabled: false
|
||||
Lint/UselessAccessModifier:
|
||||
Enabled: false
|
||||
Style/CommentIndentation:
|
||||
|
|
|
@ -77,7 +77,7 @@ class Store
|
|||
# remove from old provider
|
||||
adapter_source.delete( item.sha )
|
||||
|
||||
logger.info "NOTICE: Moved file #{item.sha} from #{source} to #{target}"
|
||||
logger.info "Moved file #{item.sha} from #{source} to #{target}"
|
||||
}
|
||||
true
|
||||
end
|
||||
|
|
|
@ -45,7 +45,7 @@ class Store::Provider::File
|
|||
|
||||
# read file from fs
|
||||
def self.read_from_fs(sha)
|
||||
Rails.logger.info "read from fs #{ get_locaton(sha) }"
|
||||
Rails.logger.debug "read from fs #{ get_locaton(sha) }"
|
||||
if !File.exist?( get_locaton(sha) )
|
||||
raise "ERROR: No such file #{ get_locaton(sha) }"
|
||||
end
|
||||
|
@ -66,7 +66,7 @@ class Store::Provider::File
|
|||
# install file
|
||||
permission = '600'
|
||||
if !File.exist?( get_locaton(sha) )
|
||||
Rails.logger.info "storge write '#{ get_locaton(sha) }' (#{permission})"
|
||||
Rails.logger.debug "storge write '#{ get_locaton(sha) }' (#{permission})"
|
||||
file = File.new( get_locaton(sha), 'wb' )
|
||||
file.write( data )
|
||||
file.close
|
||||
|
|
|
@ -3,7 +3,7 @@ end
|
|||
module Import::OTRS
|
||||
def self.request(part)
|
||||
url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key')
|
||||
puts 'GET: ' + url
|
||||
Rails.logger.info 'GET: ' + url
|
||||
response = UserAgent.request(
|
||||
url,
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ module Import::OTRS
|
|||
},
|
||||
)
|
||||
if !response.success?
|
||||
puts "ERROR: #{response.error}"
|
||||
Rails.logger.info "ERROR: #{response.error}"
|
||||
return
|
||||
end
|
||||
response
|
||||
|
@ -20,7 +20,7 @@ module Import::OTRS
|
|||
def self.post(base, data)
|
||||
url = Setting.get('import_otrs_endpoint') + '/' + base
|
||||
data['Key'] = Setting.get('import_otrs_endpoint_key')
|
||||
puts 'POST: ' + url
|
||||
Rails.logger.info 'POST: ' + url
|
||||
response = UserAgent.request(
|
||||
url,
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ module Import::OTRS
|
|||
},
|
||||
)
|
||||
if !response.success?
|
||||
puts "ERROR: #{response.error}"
|
||||
Rails.logger.info "ERROR: #{response.error}"
|
||||
return
|
||||
end
|
||||
response
|
||||
|
@ -110,7 +110,7 @@ module Import::OTRS
|
|||
end
|
||||
|
||||
def self.start
|
||||
puts 'Start import...'
|
||||
Rails.logger.info 'Start import...'
|
||||
|
||||
# # set system in import mode
|
||||
# Setting.set('import_mode', true)
|
||||
|
@ -150,14 +150,14 @@ module Import::OTRS
|
|||
(1..thread_count).each {|thread|
|
||||
threads[thread] = Thread.new {
|
||||
sleep thread * 3
|
||||
puts "Started import thread# #{thread} ..."
|
||||
Rails.logger.info "Started import thread# #{thread} ..."
|
||||
run = true
|
||||
while run
|
||||
ticket_ids = result.pop(20)
|
||||
if !ticket_ids.empty?
|
||||
self.ticket(ticket_ids)
|
||||
else
|
||||
puts "... thread# #{thread}, no more work."
|
||||
Rails.logger.info "... thread# #{thread}, no more work."
|
||||
run = false
|
||||
end
|
||||
end
|
||||
|
@ -176,7 +176,7 @@ module Import::OTRS
|
|||
end
|
||||
|
||||
def self.diff
|
||||
puts 'Start diff...'
|
||||
Rails.logger.info 'Start diff...'
|
||||
|
||||
# check if system is in import mode
|
||||
if !Setting.get('import_mode')
|
||||
|
@ -222,7 +222,7 @@ module Import::OTRS
|
|||
end
|
||||
|
||||
def self._ticket_result(result)
|
||||
# puts result.inspect
|
||||
# Rails.logger.info result.inspect
|
||||
map = {
|
||||
Ticket: {
|
||||
Changed: :updated_at,
|
||||
|
@ -283,12 +283,12 @@ module Import::OTRS
|
|||
ticket_new[value] = record['Ticket'][key.to_s]
|
||||
end
|
||||
}
|
||||
# puts key.to_s
|
||||
# puts value.to_s
|
||||
#puts 'new ticket data ' + ticket_new.inspect
|
||||
# Rails.logger.info key.to_s
|
||||
# Rails.logger.info value.to_s
|
||||
#Rails.logger.info 'new ticket data ' + ticket_new.inspect
|
||||
# check if state already exists
|
||||
ticket_old = Ticket.where( id: ticket_new[:id] ).first
|
||||
#puts 'TICKET OLD ' + ticket_old.inspect
|
||||
#Rails.logger.info 'TICKET OLD ' + ticket_old.inspect
|
||||
# find user
|
||||
if ticket_new[:owner]
|
||||
user = User.lookup( login: ticket_new[:owner] )
|
||||
|
@ -310,13 +310,13 @@ module Import::OTRS
|
|||
else
|
||||
ticket_new[:customer_id] = 1
|
||||
end
|
||||
# puts 'ttt' + ticket_new.inspect
|
||||
# Rails.logger.info 'ttt' + ticket_new.inspect
|
||||
# set state types
|
||||
if ticket_old
|
||||
puts "update Ticket.find(#{ticket_new[:id]})"
|
||||
Rails.logger.info "update Ticket.find(#{ticket_new[:id]})"
|
||||
ticket_old.update_attributes(ticket_new)
|
||||
else
|
||||
puts "add Ticket.find(#{ticket_new[:id]})"
|
||||
Rails.logger.info "add Ticket.find(#{ticket_new[:id]})"
|
||||
ticket = Ticket.new(ticket_new)
|
||||
ticket.id = ticket_new[:id]
|
||||
ticket.save
|
||||
|
@ -412,14 +412,14 @@ module Import::OTRS
|
|||
end
|
||||
article_new.delete( :type )
|
||||
article_old = Ticket::Article.where( id: article_new[:id] ).first
|
||||
#puts 'ARTICLE OLD ' + article_old.inspect
|
||||
#Rails.logger.info 'ARTICLE OLD ' + article_old.inspect
|
||||
# set state types
|
||||
if article_old
|
||||
puts "update Ticket::Article.find(#{article_new[:id]})"
|
||||
# puts article_new.inspect
|
||||
Rails.logger.info "update Ticket::Article.find(#{article_new[:id]})"
|
||||
# Rails.logger.info article_new.inspect
|
||||
article_old.update_attributes(article_new)
|
||||
else
|
||||
puts "add Ticket::Article.find(#{article_new[:id]})"
|
||||
Rails.logger.info "add Ticket::Article.find(#{article_new[:id]})"
|
||||
article = Ticket::Article.new(article_new)
|
||||
article.id = article_new[:id]
|
||||
article.save
|
||||
|
@ -428,8 +428,8 @@ module Import::OTRS
|
|||
}
|
||||
|
||||
record['History'].each { |history|
|
||||
# puts '-------'
|
||||
# puts history.inspect
|
||||
# Rails.logger.info '-------'
|
||||
# Rails.logger.info history.inspect
|
||||
if history['HistoryType'] == 'NewTicket'
|
||||
History.add(
|
||||
id: history['HistoryID'],
|
||||
|
@ -457,7 +457,7 @@ module Import::OTRS
|
|||
to_id = state_to.id
|
||||
end
|
||||
end
|
||||
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
|
||||
# Rails.logger.info "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
|
||||
History.add(
|
||||
id: history['HistoryID'],
|
||||
o_id: history['TicketID'],
|
||||
|
@ -545,7 +545,7 @@ module Import::OTRS
|
|||
return if !response.success?
|
||||
|
||||
result = json(response)
|
||||
# puts result.inspect
|
||||
# Rails.logger.info result.inspect
|
||||
map = {
|
||||
ChangeTime: :updated_at,
|
||||
CreateTime: :created_at,
|
||||
|
@ -578,7 +578,7 @@ module Import::OTRS
|
|||
|
||||
# check if state already exists
|
||||
state_old = Ticket::State.where( id: state_new[:id] ).first
|
||||
# puts 'st: ' + state['TypeName']
|
||||
# Rails.logger.info 'st: ' + state['TypeName']
|
||||
|
||||
# set state types
|
||||
if state['TypeName'] == 'pending auto'
|
||||
|
@ -587,7 +587,7 @@ module Import::OTRS
|
|||
state_type = Ticket::StateType.where( name: state['TypeName'] ).first
|
||||
state_new[:state_type_id] = state_type.id
|
||||
if state_old
|
||||
# puts 'TS: ' + state_new.inspect
|
||||
# Rails.logger.info 'TS: ' + state_new.inspect
|
||||
state_old.update_attributes(state_new)
|
||||
else
|
||||
state = Ticket::State.new(state_new)
|
||||
|
@ -705,7 +705,7 @@ module Import::OTRS
|
|||
}
|
||||
|
||||
result.each { |user|
|
||||
# puts 'USER: ' + user.inspect
|
||||
# Rails.logger.info 'USER: ' + user.inspect
|
||||
_set_valid(user)
|
||||
|
||||
role = Role.lookup( name: 'Agent' )
|
||||
|
@ -727,13 +727,13 @@ module Import::OTRS
|
|||
|
||||
# set state types
|
||||
if user_old
|
||||
puts "update User.find(#{user_new[:id]})"
|
||||
# puts 'Update User' + user_new.inspect
|
||||
Rails.logger.info "update User.find(#{user_new[:id]})"
|
||||
# Rails.logger.info 'Update User' + user_new.inspect
|
||||
user_new.delete( :role_ids )
|
||||
user_old.update_attributes(user_new)
|
||||
else
|
||||
puts "add User.find(#{user_new[:id]})"
|
||||
# puts 'Add User' + user_new.inspect
|
||||
Rails.logger.info "add User.find(#{user_new[:id]})"
|
||||
# Rails.logger.info 'Add User' + user_new.inspect
|
||||
user = User.new(user_new)
|
||||
user.id = user_new[:id]
|
||||
user.save
|
||||
|
@ -745,7 +745,7 @@ module Import::OTRS
|
|||
count = 0
|
||||
while done == false
|
||||
sleep 2
|
||||
puts "Count=#{count};Offset=#{count}"
|
||||
Rails.logger.info "Count=#{count};Offset=#{count}"
|
||||
response = request( "public.pl?Action=Export;Type=Customer;Count=100;Offset=#{count}" )
|
||||
return if !response
|
||||
count = count + 3000
|
||||
|
@ -798,12 +798,12 @@ module Import::OTRS
|
|||
|
||||
# set state types
|
||||
if user_old
|
||||
puts "update User.find(#{user_new[:id]})"
|
||||
# puts 'Update User' + user_new.inspect
|
||||
Rails.logger.info "update User.find(#{user_new[:id]})"
|
||||
# Rails.logger.info 'Update User' + user_new.inspect
|
||||
user_old.update_attributes(user_new)
|
||||
else
|
||||
# puts 'Add User' + user_new.inspect
|
||||
puts "add User.find(#{user_new[:id]})"
|
||||
# Rails.logger.info 'Add User' + user_new.inspect
|
||||
Rails.logger.info "add User.find(#{user_new[:id]})"
|
||||
user = User.new(user_new)
|
||||
user.save
|
||||
end
|
||||
|
|
|
@ -797,7 +797,6 @@ module Import::OTRS2
|
|||
|
||||
# check if state already exists
|
||||
state_old = Ticket::State.where( id: state_new[:id] ).first
|
||||
# puts 'st: ' + state['TypeName']
|
||||
|
||||
# set state types
|
||||
if state['TypeName'] == 'pending auto'
|
||||
|
@ -806,7 +805,6 @@ module Import::OTRS2
|
|||
state_type = Ticket::StateType.where( name: state['TypeName'] ).first
|
||||
state_new[:state_type_id] = state_type.id
|
||||
if state_old
|
||||
# puts 'TS: ' + state_new.inspect
|
||||
state_old.update_attributes(state_new)
|
||||
else
|
||||
state = Ticket::State.new(state_new)
|
||||
|
@ -1185,7 +1183,7 @@ module Import::OTRS2
|
|||
# log
|
||||
def self.log(message)
|
||||
thread_no = Thread.current[:thread_no] || '-'
|
||||
puts "#{Time.new.to_s}/thread##{thread_no}: #{message}"
|
||||
Rails.logger.info "thread##{thread_no}: #{message}"
|
||||
end
|
||||
|
||||
# set translate valid ids to active = true|false
|
||||
|
|
Loading…
Reference in a new issue