Improved background job for import.
This commit is contained in:
parent
edf565bd4d
commit
f2d0eca3da
5 changed files with 115 additions and 42 deletions
|
@ -18,12 +18,6 @@ class Index extends App.ControllerContent
|
||||||
|
|
||||||
@fetch()
|
@fetch()
|
||||||
|
|
||||||
@bind('import:finished', =>
|
|
||||||
console.log('import:finished')
|
|
||||||
@Config.set('system_init_done', true)
|
|
||||||
@navigate '#'
|
|
||||||
)
|
|
||||||
|
|
||||||
fetch: ->
|
fetch: ->
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
|
@ -106,8 +100,6 @@ class Index extends App.ControllerContent
|
||||||
url: @apiPath + '/import/otrs/import_start',
|
url: @apiPath + '/import/otrs/import_start',
|
||||||
processData: true,
|
processData: true,
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
|
|
||||||
# validate form
|
|
||||||
if data.result is 'ok'
|
if data.result is 'ok'
|
||||||
@delay(@updateMigration, 3000)
|
@delay(@updateMigration, 3000)
|
||||||
)
|
)
|
||||||
|
@ -127,6 +119,13 @@ class Index extends App.ControllerContent
|
||||||
@navigate '#'
|
@navigate '#'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if data.result is 'error'
|
||||||
|
@$('.js-error').removeClass('hide')
|
||||||
|
@$('.js-error').html(App.i18n.translateContent(data.message))
|
||||||
|
else
|
||||||
|
@$('.js-error').addClass('hide')
|
||||||
|
|
||||||
|
if data.result is 'in_progress'
|
||||||
for key, item of data.data
|
for key, item of data.data
|
||||||
element = @$('.js-' + key.toLowerCase() )
|
element = @$('.js-' + key.toLowerCase() )
|
||||||
element.find('.js-done').text(item.done)
|
element.find('.js-done').text(item.done)
|
||||||
|
@ -137,7 +136,7 @@ class Index extends App.ControllerContent
|
||||||
element.addClass('is-done')
|
element.addClass('is-done')
|
||||||
else
|
else
|
||||||
element.removeClass('is-done')
|
element.removeClass('is-done')
|
||||||
@delay( @updateMigration, 5000 )
|
@delay(@updateMigration, 6500)
|
||||||
)
|
)
|
||||||
|
|
||||||
App.Config.set( 'import/otrs', Index, 'Routes' )
|
App.Config.set( 'import/otrs', Index, 'Routes' )
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
|
|
||||||
<div class="wizard-slide vertical hide" data-slide="otrs-import">
|
<div class="wizard-slide vertical hide" data-slide="otrs-import">
|
||||||
<h2><%- @T('OTRS Migration') %></h2>
|
<h2><%- @T('OTRS Migration') %></h2>
|
||||||
|
<div class="alert alert--danger hide js-error" role="alert"></div>
|
||||||
|
|
||||||
<div class="wizard-body flex vertical justified">
|
<div class="wizard-body flex vertical justified">
|
||||||
<table class="progressTable">
|
<table class="progressTable">
|
||||||
<tr class="js-config">
|
<tr class="js-config">
|
||||||
|
|
|
@ -80,7 +80,6 @@ class ImportOtrsController < ApplicationController
|
||||||
|
|
||||||
def import_start
|
def import_start
|
||||||
return if setup_done_response
|
return if setup_done_response
|
||||||
|
|
||||||
Setting.set('import_mode', true)
|
Setting.set('import_mode', true)
|
||||||
welcome = Import::OTRS.connection_test
|
welcome = Import::OTRS.connection_test
|
||||||
if !welcome
|
if !welcome
|
||||||
|
@ -92,7 +91,10 @@ class ImportOtrsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# start migration
|
# start migration
|
||||||
Import::OTRS.delay.start
|
Import::OTRS.delay.start_bg(
|
||||||
|
import_otrs_endpoint: Setting.get('import_otrs_endpoint'),
|
||||||
|
import_otrs_endpoint_key: Setting.get('import_otrs_endpoint_key'),
|
||||||
|
)
|
||||||
|
|
||||||
render json: {
|
render json: {
|
||||||
result: 'ok',
|
result: 'ok',
|
||||||
|
@ -100,18 +102,11 @@ class ImportOtrsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_status
|
def import_status
|
||||||
if !Setting.get('import_mode')
|
result = Import::OTRS.status_bg
|
||||||
render json: {
|
if result[:setup_done] == true
|
||||||
setup_done: true,
|
Setting.reload
|
||||||
}
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
render json: result
|
||||||
state = Import::OTRS.current_state
|
|
||||||
render json: {
|
|
||||||
data: state,
|
|
||||||
result: 'in_progress',
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -77,13 +77,25 @@ reset config setting to default
|
||||||
@@current[:settings_config][name]
|
@@current[:settings_config][name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
reload config settings
|
||||||
|
|
||||||
|
Setting.reload
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.reload
|
||||||
|
load(true)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# load values and cache them
|
# load values and cache them
|
||||||
def self.load
|
def self.load(force = false)
|
||||||
|
|
||||||
# check if config is already generated
|
# check if config is already generated
|
||||||
if @@current[:settings_config]
|
if !force && @@current[:settings_config]
|
||||||
return false if cache_valid?
|
return false if cache_valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ module Import::OTRS
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
get object statistic from server ans save it in cache
|
get object statistic from remote server ans save it in cache
|
||||||
|
|
||||||
result = statistic('Subaction=List')
|
result = statistic('Subaction=List')
|
||||||
|
|
||||||
|
@ -409,15 +409,80 @@ module Import::OTRS
|
||||||
threads[thread].join
|
threads[thread].join
|
||||||
}
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
start import in background
|
||||||
|
|
||||||
|
Import::OTRS.start_bg(
|
||||||
|
import_otrs_endpoint: 'http://vz599.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator
|
||||||
|
',
|
||||||
|
import_otrs_endpoint_key: '01234567899876543210',
|
||||||
|
)
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.start_bg(params)
|
||||||
|
Setting.set('import_mode', 'true')
|
||||||
|
Setting.set('import_backend', 'otrs')
|
||||||
|
Setting.set('import_otrs_endpoint', params[:import_otrs_endpoint])
|
||||||
|
Setting.set('import_otrs_endpoint_key', params[:import_otrs_endpoint_key])
|
||||||
|
|
||||||
|
status_update_thread = Thread.new {
|
||||||
|
loop do
|
||||||
|
result = {
|
||||||
|
data: current_state,
|
||||||
|
result: 'in_progress',
|
||||||
|
}
|
||||||
|
Cache.write('import:state', result, expires_in: 10.minutes)
|
||||||
|
sleep 8
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
begin
|
||||||
|
import_thread = Thread.new {
|
||||||
|
Import::OTRS.start
|
||||||
|
}
|
||||||
|
rescue => e
|
||||||
|
status_update_thread.exit
|
||||||
|
status_update_thread.join
|
||||||
|
Rails.logger.error e.message
|
||||||
|
Rails.logger.error e.backtrace.inspect
|
||||||
|
result = {
|
||||||
|
message: e.message,
|
||||||
|
result: 'error',
|
||||||
|
}
|
||||||
|
Cache.write('import:state', result, expires_in: 10.hours)
|
||||||
|
end
|
||||||
|
import_thread.join
|
||||||
|
status_update_thread.exit
|
||||||
|
status_update_thread.join
|
||||||
|
|
||||||
Setting.set('system_init_done', true)
|
Setting.set('system_init_done', true)
|
||||||
Setting.set('import_mode', false)
|
Setting.set('import_mode', false)
|
||||||
|
end
|
||||||
|
|
||||||
# broadcast import finish
|
=begin
|
||||||
Sessions.broadcast(
|
|
||||||
event: 'import:finished',
|
|
||||||
)
|
|
||||||
|
|
||||||
true
|
get import state from background process
|
||||||
|
|
||||||
|
result = Import::OTRS.status_bg
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.status_bg
|
||||||
|
if !Setting.get('import_mode')
|
||||||
|
return {
|
||||||
|
setup_done: true,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
state = Cache.get('import:state')
|
||||||
|
return state if state
|
||||||
|
{
|
||||||
|
message: 'not running',
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.diff_worker
|
def self.diff_worker
|
||||||
|
|
Loading…
Reference in a new issue