2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
module Async
|
|
|
|
# rubocop:disable Style/ModuleFunction
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def start_bg
|
|
|
|
Setting.reload
|
|
|
|
|
|
|
|
Import::OTRS::Requester.connection_test
|
|
|
|
|
|
|
|
# start thread to observe current state
|
2017-10-01 12:25:52 +00:00
|
|
|
status_update_thread = Thread.new do
|
2016-11-25 16:10:37 +00:00
|
|
|
loop do
|
|
|
|
result = {
|
2018-12-19 17:31:51 +00:00
|
|
|
data: current_state,
|
2016-11-25 16:10:37 +00:00
|
|
|
result: 'in_progress',
|
|
|
|
}
|
|
|
|
Cache.write('import:state', result, expires_in: 10.minutes)
|
|
|
|
sleep 8
|
|
|
|
end
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# start import data
|
|
|
|
begin
|
|
|
|
Import::OTRS.start
|
|
|
|
rescue => e
|
|
|
|
status_update_thread.exit
|
|
|
|
status_update_thread.join
|
2017-04-19 10:09:54 +00:00
|
|
|
Rails.logger.error e
|
2016-11-25 16:10:37 +00:00
|
|
|
result = {
|
|
|
|
message: e.message,
|
2018-12-19 17:31:51 +00:00
|
|
|
result: 'error',
|
2016-11-25 16:10:37 +00:00
|
|
|
}
|
|
|
|
Cache.write('import:state', result, expires_in: 10.hours)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
sleep 16 # wait until new finished import state is on client
|
|
|
|
status_update_thread.exit
|
|
|
|
status_update_thread.join
|
|
|
|
|
|
|
|
result = {
|
|
|
|
result: 'import_done',
|
|
|
|
}
|
|
|
|
Cache.write('import:state', result, expires_in: 10.hours)
|
|
|
|
|
|
|
|
Setting.set('system_init_done', true)
|
|
|
|
Setting.set('import_mode', false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_bg
|
2021-05-31 13:05:54 +00:00
|
|
|
state = Cache.read('import:state')
|
2016-11-25 16:10:37 +00:00
|
|
|
return state if state
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
{
|
|
|
|
message: 'not running',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|