ixport 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/ixport/application_controller.rb +2 -1
- data/app/controllers/ixport/export_templates_controller.rb +14 -5
- data/app/controllers/ixport/runs_controller.rb +17 -4
- data/app/models/ixport/export_template.rb +2 -0
- data/app/models/ixport/import.rb +13 -4
- data/app/models/ixport/wallflower_task_runner.rb +2 -2
- data/app/views/ixport/export_templates/edit.html.erb +1 -1
- data/app/views/ixport/export_templates/new.html.erb +1 -1
- data/app/views/ixport/imports/show.html.erb +7 -2
- data/app/views/ixport/previews/show.html.erb +3 -0
- data/lib/ixport/version.rb +1 -1
- 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: b40a581b96b5e012197ee7a185f08891e4580fb7f2bc824ddd5de3789ccb9e02
|
|
4
|
+
data.tar.gz: 9f6e9bde4f0590cfac3524df4695bff2ee132ad47cd8d66938b919fbf5ec2c67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f3dde1eac2e6e592a49fcf9049c822efa56e70468cbe1666329c8be35beef75e94e03091786bf94f8f0f141619e48a338fa99ecc1b349f6e547461569a7d12d
|
|
7
|
+
data.tar.gz: 0af9d0471ea9d3e62a0476e1e6ef9a7fa8d9bff8050e90576d7d226e53c620bf90f62261930e52a43a9115b3a97b4b5d0daa450b999d618c3576f2a61bd1db35
|
|
@@ -13,7 +13,8 @@ module Ixport
|
|
|
13
13
|
|
|
14
14
|
def find_import
|
|
15
15
|
@import = Import.find_by(id: params[:import_id] || params[:id], person: ixport_person, account: ixport_account)
|
|
16
|
-
|
|
16
|
+
registration = @import && Ixport.registrations[@import.key.to_sym]
|
|
17
|
+
head :not_found unless registration && allowed?(registration)
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def ixport_person
|
|
@@ -10,8 +10,12 @@ module Ixport
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def create
|
|
13
|
-
ExportTemplate.
|
|
14
|
-
redirect_to exports_path
|
|
13
|
+
template = ExportTemplate.new(key: @registration.key, name: params[:name], columns: known_columns(@registration), person: ixport_person, account: ixport_account)
|
|
14
|
+
return redirect_to exports_path if template.save
|
|
15
|
+
|
|
16
|
+
@columns = @registration.exporter.constantize.columns
|
|
17
|
+
@name_error = template.errors[:name].first
|
|
18
|
+
render :new, status: :unprocessable_entity
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
def show
|
|
@@ -24,8 +28,12 @@ module Ixport
|
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
def update
|
|
27
|
-
@template.update
|
|
28
|
-
|
|
31
|
+
return redirect_to exports_path if @template.update(name: params[:name], columns: known_columns(@template.registration))
|
|
32
|
+
|
|
33
|
+
@columns = @template.registration.exporter.constantize.columns
|
|
34
|
+
@name_error = @template.errors[:name].first
|
|
35
|
+
@template.restore_attributes
|
|
36
|
+
render :edit, status: :unprocessable_entity
|
|
29
37
|
end
|
|
30
38
|
|
|
31
39
|
def destroy
|
|
@@ -37,7 +45,8 @@ module Ixport
|
|
|
37
45
|
|
|
38
46
|
def find_template
|
|
39
47
|
@template = ExportTemplate.find_by(id: params[:id], account: ixport_account)
|
|
40
|
-
|
|
48
|
+
registration = @template && Ixport.export_registrations[@template.key.to_sym]
|
|
49
|
+
head :not_found unless registration && allowed?(registration)
|
|
41
50
|
end
|
|
42
51
|
|
|
43
52
|
def find_chosen_export
|
|
@@ -7,15 +7,28 @@ module Ixport
|
|
|
7
7
|
def create
|
|
8
8
|
runner = Ixport.background_runner
|
|
9
9
|
return run_in_request unless runner
|
|
10
|
-
return redirect_to import_path(@import) unless
|
|
10
|
+
return redirect_to import_path(@import) unless claim_pending_import
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
runner.enqueue(@import)
|
|
14
|
-
redirect_to @import.wallflower_task_id ? wallflower.task_path(@import.wallflower_task_id) : import_path(@import)
|
|
12
|
+
hand_over(runner)
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
private
|
|
18
16
|
|
|
17
|
+
def claim_pending_import
|
|
18
|
+
claimed = Import.where(id: @import.id, status: "pending").update_all(status: "running", updated_at: Time.current) == 1
|
|
19
|
+
@import.reload if claimed
|
|
20
|
+
claimed
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def hand_over(runner)
|
|
24
|
+
runner.enqueue(@import)
|
|
25
|
+
redirect_to @import.wallflower_task_id ? wallflower.task_path(@import.wallflower_task_id) : import_path(@import)
|
|
26
|
+
rescue StandardError => error
|
|
27
|
+
Rails.error.report(error)
|
|
28
|
+
@import.update!(status: "pending")
|
|
29
|
+
redirect_to import_preview_path(@import), flash: { ixport_not_started: true }
|
|
30
|
+
end
|
|
31
|
+
|
|
19
32
|
def run_in_request
|
|
20
33
|
@import.run!
|
|
21
34
|
redirect_to import_path(@import)
|
data/app/models/ixport/import.rb
CHANGED
|
@@ -12,11 +12,15 @@ module Ixport
|
|
|
12
12
|
has_one_attached :file
|
|
13
13
|
has_many :refusals, -> { order(:row_number) }, class_name: "Ixport::ImportRefusal", dependent: :destroy
|
|
14
14
|
|
|
15
|
+
STALLED_AFTER = 1.hour
|
|
16
|
+
|
|
15
17
|
validate :incoming_file_is_usable, on: :create
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
attr_reader :run_error
|
|
20
|
+
|
|
21
|
+
def run!(reporter: NullReporter.new, report_failure: true)
|
|
18
22
|
with_lock do
|
|
19
|
-
walk_and_save(reporter) if status.in?(%w[pending running])
|
|
23
|
+
walk_and_save(reporter, report_failure) if status.in?(%w[pending running])
|
|
20
24
|
end
|
|
21
25
|
end
|
|
22
26
|
|
|
@@ -28,6 +32,10 @@ module Ixport
|
|
|
28
32
|
status == "running"
|
|
29
33
|
end
|
|
30
34
|
|
|
35
|
+
def stalled?
|
|
36
|
+
running? && updated_at < STALLED_AFTER.ago
|
|
37
|
+
end
|
|
38
|
+
|
|
31
39
|
def failed?
|
|
32
40
|
status == "failed"
|
|
33
41
|
end
|
|
@@ -72,7 +80,7 @@ module Ixport
|
|
|
72
80
|
|
|
73
81
|
private
|
|
74
82
|
|
|
75
|
-
def walk_and_save(reporter)
|
|
83
|
+
def walk_and_save(reporter, report_failure)
|
|
76
84
|
counts = { add: 0, update: 0 }
|
|
77
85
|
rows = self.rows
|
|
78
86
|
reporter.set_total(rows.size)
|
|
@@ -83,7 +91,8 @@ module Ixport
|
|
|
83
91
|
end
|
|
84
92
|
update!(status: "finished", added_count: counts[:add], updated_count: counts[:update])
|
|
85
93
|
rescue StandardError => error
|
|
86
|
-
|
|
94
|
+
@run_error = error
|
|
95
|
+
Rails.error.report(error) if report_failure
|
|
87
96
|
update!(status: "failed", error_message: error.message, added_count: counts[:add], updated_count: counts[:update])
|
|
88
97
|
end
|
|
89
98
|
|
|
@@ -6,9 +6,9 @@ module Ixport
|
|
|
6
6
|
|
|
7
7
|
def call(task)
|
|
8
8
|
import = Import.find(task.params["import_id"])
|
|
9
|
-
|
|
9
|
+
import.run!(reporter: task, report_failure: false)
|
|
10
10
|
task.link_result(ixport.import_path(import))
|
|
11
|
-
raise ImportFailed
|
|
11
|
+
raise(import.run_error || ImportFailed.new(import.error_message)) if import.failed?
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<%= ui_form_page(title: "Edit #{@template.name}", subtitle: @template.registration.title, back_url: exports_path) %>
|
|
2
2
|
<%= ui_page(max_width: :md) do %>
|
|
3
3
|
<%= ui_form(action: export_template_path(@template), method: :patch) do %>
|
|
4
|
-
<%= ui_form_field(attribute: "name", label: "Template name", required: true, value: @template.name) %>
|
|
4
|
+
<%= ui_form_field(attribute: "name", label: "Template name", required: true, value: @template.name, errors: @name_error.present? ? [tag.span(@name_error, data: { name_error: true })] : []) %>
|
|
5
5
|
<% column_options = @columns.map { |column| [column.label, column.key] } %>
|
|
6
6
|
<% @columns.each_index do |index| %>
|
|
7
7
|
<%= ui_form_field(attribute: "columns[]", label: "Column #{index + 1}", type: :select, options: column_options, include_blank: "None", value: @template.columns[index]) %>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<%= ui_form_page(title: "New #{@registration.title} template", back_url: exports_path) %>
|
|
2
2
|
<%= ui_page(max_width: :md) do %>
|
|
3
3
|
<%= ui_form(action: export_templates_path(@registration.key)) do %>
|
|
4
|
-
<%= ui_form_field(attribute: "name", label: "Template name", required: true) %>
|
|
4
|
+
<%= ui_form_field(attribute: "name", label: "Template name", required: true, errors: @name_error.present? ? [tag.span(@name_error, data: { name_error: true })] : []) %>
|
|
5
5
|
<% column_options = @columns.map { |column| [column.label, column.key] } %>
|
|
6
6
|
<% @columns.each_index do |index| %>
|
|
7
7
|
<%= ui_form_field(attribute: "columns[]", label: "Column #{index + 1}", type: :select, options: column_options, include_blank: "None") %>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
<% heading = if @import.
|
|
1
|
+
<% heading = if @import.stalled?
|
|
2
|
+
"Import stalled"
|
|
3
|
+
elsif @import.running?
|
|
2
4
|
"Import running"
|
|
3
5
|
elsif @import.failed?
|
|
4
6
|
"Import failed"
|
|
@@ -8,7 +10,10 @@
|
|
|
8
10
|
<%= ui_show_page(title: heading, back_url: root_path) %>
|
|
9
11
|
<%= ui_page(max_width: :md) do %>
|
|
10
12
|
<%= ui_page_header(title: heading) %>
|
|
11
|
-
<% if @import.
|
|
13
|
+
<% if @import.stalled? %>
|
|
14
|
+
<%= ui_alert(type: :error, message: tag.span("This import has stopped making progress.", data: { import_stalled: true })) %>
|
|
15
|
+
<p>Rows saved before it stopped stay saved.</p>
|
|
16
|
+
<% elsif @import.running? %>
|
|
12
17
|
<%= ui_alert(type: :info, message: tag.span("This import is running.", data: { import_running: true })) %>
|
|
13
18
|
<% else %>
|
|
14
19
|
<% if @import.failed? %>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<%= ui_show_page(title: "Preview", back_url: import_mapping_path(@import)) %>
|
|
2
2
|
<%= ui_page(max_width: :md) do %>
|
|
3
3
|
<%= ui_page_header(title: "Preview") %>
|
|
4
|
+
<% if flash[:ixport_not_started].present? %>
|
|
5
|
+
<%= ui_alert(type: :error, message: tag.span("This import did not start. Run it again.", data: { import_not_started: true })) %>
|
|
6
|
+
<% end %>
|
|
4
7
|
<%= ui_grid(cols: { default: 1, sm: 3 }) do %>
|
|
5
8
|
<%= ui_stat_card(label: "Will add", value: tag.span(@counts[:add], data: { count: "add" })) %>
|
|
6
9
|
<%= ui_stat_card(label: "Will update", value: tag.span(@counts[:update], data: { count: "update" })) %>
|
data/lib/ixport/version.rb
CHANGED