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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db26aed7616f6b7cde6bd010cebee8596832a72f4aae13e1960add0a6b12862f
4
- data.tar.gz: e62ab3e9aa286845ff91e0b6c0d8e2a964428e60020745f008adf566c541361c
3
+ metadata.gz: 3b130c09a6196e7ffa64638bc95608ccfd6db8c93ac68d67d008d3fb84863fb6
4
+ data.tar.gz: cdd29e415e7bf29150544cd2c3efaff13e7a56f3e111aa24ac1976fa83ffd7cd
5
5
  SHA512:
6
- metadata.gz: 791ab59aa1a6df01bca499cbfe632dcf31a450bb1485589c729f2460498f7c87163d5f9249302b9fd66ae2b618c34b1a548ccf056d933dbd3cabce74698708d9
7
- data.tar.gz: 8016421a65bf3dfbfe04f29928904f118bf7862915f784053871cae78fa69a5fbd0947c874f08a1aa51db474b658f147fa08838df8ed8953682a911498f8587f
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
- import.update(state: import.import_lines.in_error.any? ? 'error' : 'imported')
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 imported importing].include? @import_file.state
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
@@ -8,6 +8,7 @@ NtqExcelsiorEngine.setup do |config|
8
8
  # user: UserImporter
9
9
  # }
10
10
 
11
+ # config.keep_import_lines = false
11
12
  # config.debug = false
12
13
  # config.async = false
13
14
  # config.actions_on_create = [:load, :check, :import]
@@ -1,3 +1,3 @@
1
1
  module NtqExcelsiorEngine
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -17,6 +17,9 @@ module NtqExcelsiorEngine
17
17
  mattr_accessor :action_cable
18
18
  @@action_cable = false
19
19
 
20
+ mattr_accessor :keep_import_lines
21
+ @@keep_import_lines = false
22
+
20
23
  mattr_accessor :debug
21
24
  @@debug = false
22
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntq_excelsior_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin