ntq_excelsior_engine 0.2.0 → 0.3.2
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 +15 -2
- 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 +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5079df1832c81393d48a170a45bf2af1d72ef5eb30115574008146f58e55a4ca
|
4
|
+
data.tar.gz: 4d3d56ea2e1a0fb9cbe7595be527ee02fc1b6234b2da97ca8a1a09c177c042b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1480ec6ea4d4d0baae5bd126f5e5d5d5cae9035ea733e1cb93c93a20c8d41f521103af4921b6e7e22a258ba251c455e1e4e8d0783d457020d0c620a207b93cc
|
7
|
+
data.tar.gz: df1616df6ad1a7bac29f84e3f7032e7f819830ba42a0b727e2f1f5d6b32c318f26375a280f79cc5160d7d35e5735c04e9bbb3ab030ccc5191a9e15af54476206
|
@@ -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(','))
|
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
|
@@ -1,13 +1,26 @@
|
|
1
|
+
|
1
2
|
json.set! :data do
|
2
3
|
json.id @import_file.id
|
3
4
|
json.state @import_file.state
|
4
5
|
if @import_file.error?
|
5
|
-
json.
|
6
|
+
json.error_message @import_file.error_message
|
7
|
+
if @import_file.error_message == "header_not_found"
|
8
|
+
json.missing_headers @import_file.backtrace.split(",")
|
9
|
+
else
|
10
|
+
json.error_file download_errors_file_url(@import_file.id)
|
11
|
+
json.backtrace @import_file.backtrace
|
12
|
+
end
|
6
13
|
end
|
7
|
-
if %[checked
|
14
|
+
if %[checked importing].include? @import_file.state
|
8
15
|
json.errors_count @import_file.import_lines.in_error.count
|
9
16
|
json.success_count @import_file.import_lines.successes.count
|
10
17
|
json.create_count @import_file.import_lines.successes.is_create.count
|
11
18
|
json.update_count @import_file.import_lines.successes.is_update.count
|
12
19
|
end
|
20
|
+
if @import_file.state == "imported"
|
21
|
+
json.errors_count @import_file.stats[:errors]
|
22
|
+
json.success_count @import_file.stats[:success]
|
23
|
+
json.create_count @import_file.stats[:create]
|
24
|
+
json.update_count @import_file.stats[:update]
|
25
|
+
end
|
13
26
|
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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntq_excelsior_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|