ntq_excelsior_engine 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ntq_excelsior_engine/importers_controller.rb +0 -16
- data/app/controllers/ntq_excelsior_engine/imports_controller.rb +1 -1
- data/app/interactors/ntq_excelsior_engine/imports/check_lines.rb +1 -1
- data/app/interactors/ntq_excelsior_engine/imports/import_lines.rb +10 -2
- data/app/interactors/ntq_excelsior_engine/imports/load_lines.rb +3 -0
- data/app/models/ntq_excelsior_engine/import.rb +1 -7
- data/app/views/ntq_excelsior_engine/imports/status.json.jbuilder +9 -1
- data/config/routes.rb +0 -1
- data/lib/generators/templates/ntq_excelsior_engine.rb +1 -0
- data/lib/ntq_excelsior_engine/version.rb +1 -1
- data/lib/ntq_excelsior_engine.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b130c09a6196e7ffa64638bc95608ccfd6db8c93ac68d67d008d3fb84863fb6
|
4
|
+
data.tar.gz: cdd29e415e7bf29150544cd2c3efaff13e7a56f3e111aa24ac1976fa83ffd7cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96b1c15d0e0e3db9450be8c89a0306a02a44157cb9347f89c360dc87aa9eb174ead679fd43b418bc8335b13c9bb8b84c89faef4804cd2fad43d6918ac8f0edee
|
7
|
+
data.tar.gz: d9199ad8903b15e5eef88f286353fd589ea492cdfe1b10ffd633475b2cd88f072c59e68be5bc991e69001cc488899e5cab922d4061a7fcebaf8c08e4b5c791ed
|
@@ -13,22 +13,6 @@ module NtqExcelsiorEngine
|
|
13
13
|
send_file "#{Rails.root}/#{@importer.to_s.constantize.sample_file}", disposition: 'attachment'
|
14
14
|
end
|
15
15
|
|
16
|
-
def status
|
17
|
-
valid_types = NtqExcelsiorEngine.importers.keys.map(&:to_s)
|
18
|
-
|
19
|
-
importing_files = NtqExcelsiorEngine::Import.importing
|
20
|
-
importing_files = importing_files.where(import_type: params[:type]) if params[:type].present? && valid_types.include?(params[:type])
|
21
|
-
|
22
|
-
job_status_json = {}
|
23
|
-
job_status_json[:refetch] = false
|
24
|
-
importing_files.each do |importing_file|
|
25
|
-
job_status_json[importing_file.import_type] = Sidekiq::Status.get_all(importing_file.job_id)
|
26
|
-
job_status_json[:refetch] = true
|
27
|
-
end
|
28
|
-
|
29
|
-
render json: { status: job_status_json }
|
30
|
-
end
|
31
|
-
|
32
16
|
private
|
33
17
|
|
34
18
|
def ensure_valid_importer_type!
|
@@ -33,7 +33,7 @@ module NtqExcelsiorEngine
|
|
33
33
|
def create
|
34
34
|
@import_file = ::NtqExcelsiorEngine::Import.new import_type: params[:type]
|
35
35
|
@import_file.file = file_params
|
36
|
-
yield(import_file) if block_given?
|
36
|
+
yield(@import_file) if block_given?
|
37
37
|
@import_file.inspect
|
38
38
|
if @import_file.save
|
39
39
|
unless NtqExcelsiorEngine.async
|
@@ -3,7 +3,7 @@ module NtqExcelsiorEngine
|
|
3
3
|
include Interactor
|
4
4
|
|
5
5
|
around do |interactor|
|
6
|
-
if context.actions && context.actions.include?("check") && context.import && context.importer
|
6
|
+
if context.actions && context.actions.include?("check") && context.import && context.importer && context.import.import_lines.any?
|
7
7
|
interactor.call
|
8
8
|
end
|
9
9
|
end
|
@@ -3,7 +3,7 @@ module NtqExcelsiorEngine
|
|
3
3
|
include Interactor
|
4
4
|
|
5
5
|
around do |interactor|
|
6
|
-
if context.actions && context.actions.include?("import") && context.import && !context.import.error? && context.importer
|
6
|
+
if context.actions && context.actions.include?("import") && context.import && !context.import.error? && context.importer && context.import.import_lines.any?
|
7
7
|
interactor.call
|
8
8
|
end
|
9
9
|
end
|
@@ -18,7 +18,15 @@ module NtqExcelsiorEngine
|
|
18
18
|
line.update(status: result[:status], line_errors: result[:errors], action: result[:action])
|
19
19
|
end
|
20
20
|
sleep 2 if NtqExcelsiorEngine.debug
|
21
|
-
|
21
|
+
stats = {
|
22
|
+
count: import.import_lines.count,
|
23
|
+
errors: import.import_lines.in_error.count,
|
24
|
+
success: import.import_lines.successes.count,
|
25
|
+
create: import.import_lines.successes.is_create.count,
|
26
|
+
update: import.import_lines.successes.is_update.count
|
27
|
+
}
|
28
|
+
import.update(state: import.import_lines.in_error.any? ? 'error' : 'imported', stats: stats)
|
29
|
+
import.import_lines.delete_all unless NtqExcelsiorEngine.keep_import_lines
|
22
30
|
rescue => e
|
23
31
|
p e.inspect
|
24
32
|
Appsignal.send_error(e)
|
@@ -25,6 +25,9 @@ module NtqExcelsiorEngine
|
|
25
25
|
sleep 2 if NtqExcelsiorEngine.debug
|
26
26
|
import.update(headers: importer.detect_header_scheme, state: 'buffered')
|
27
27
|
import.temp_file.unlink
|
28
|
+
rescue Roo::HeaderRowNotFoundError => e
|
29
|
+
message = e.message.gsub("\/i", "").gsub("/", "").slice(1..-1).chop
|
30
|
+
import.update(state: 'error', error_message: 'header_not_found', backtrace: message.split(', ').join('\n'))
|
28
31
|
rescue => e
|
29
32
|
Appsignal.send_error(e)
|
30
33
|
import.update(state: 'error', backtrace: e.backtrace.join('\n'))
|
@@ -1,11 +1,5 @@
|
|
1
1
|
module NtqExcelsiorEngine
|
2
2
|
class Import < ::ApplicationRecord
|
3
|
-
VALID_CONTENT_TYPES = %w[
|
4
|
-
application/vnd.ms-excel
|
5
|
-
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
6
|
-
application/vnd.ms-excel.sheet.macroenabled.12
|
7
|
-
application/vnd.ms-excel.sheet.macroEnabled.12
|
8
|
-
].freeze
|
9
3
|
|
10
4
|
self.table_name = "excelsior_imports"
|
11
5
|
|
@@ -16,7 +10,7 @@ module NtqExcelsiorEngine
|
|
16
10
|
serialize :stats, Hash
|
17
11
|
|
18
12
|
has_one_attached :file
|
19
|
-
has_many :import_lines, foreign_key: :excelsior_import_id
|
13
|
+
has_many :import_lines, foreign_key: :excelsior_import_id, dependent: :delete_all
|
20
14
|
|
21
15
|
validates :file, presence: true
|
22
16
|
validates :state, presence: true
|
@@ -3,11 +3,19 @@ json.set! :data do
|
|
3
3
|
json.state @import_file.state
|
4
4
|
if @import_file.error?
|
5
5
|
json.error_file download_errors_file_url(@import_file.id)
|
6
|
+
json.error_message @import_file.error_message
|
7
|
+
json.backtrace @import_file.backtrace
|
6
8
|
end
|
7
|
-
if %[checked
|
9
|
+
if %[checked importing].include? @import_file.state
|
8
10
|
json.errors_count @import_file.import_lines.in_error.count
|
9
11
|
json.success_count @import_file.import_lines.successes.count
|
10
12
|
json.create_count @import_file.import_lines.successes.is_create.count
|
11
13
|
json.update_count @import_file.import_lines.successes.is_update.count
|
12
14
|
end
|
15
|
+
if @import_file.state == "imported"
|
16
|
+
json.errors_count @import_file.stats[:errors]
|
17
|
+
json.success_count @import_file.stats[:success]
|
18
|
+
json.create_count @import_file.stats[:create]
|
19
|
+
json.update_count @import_file.stats[:update]
|
20
|
+
end
|
13
21
|
end
|
data/config/routes.rb
CHANGED
@@ -3,7 +3,6 @@ NtqExcelsiorEngine::Engine.routes.draw do
|
|
3
3
|
get 'importers/show'
|
4
4
|
get '/importers/:type' => "importers#show"
|
5
5
|
get '/importers/:type/sample_file' => "importers#sample_file", as: :download_sample_file
|
6
|
-
get '/importers/status' => "importers#status"
|
7
6
|
|
8
7
|
post '/imports/:type' => "imports#create"
|
9
8
|
get '/imports/:id/export_errors' => "imports#export_errors", as: :download_errors_file
|
data/lib/ntq_excelsior_engine.rb
CHANGED