eco-helpers 3.2.2 → 3.2.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/.rubocop.yml +1 -1
- data/CHANGELOG.md +16 -1
- data/eco-helpers.gemspec +2 -2
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +1 -0
- data/lib/eco/api/common/people/person_entry.rb +1 -1
- data/lib/eco/api/common/people/person_parser.rb +1 -0
- data/lib/eco/api/organization/tag_tree.rb +11 -4
- data/lib/eco/api/usecases/default/locations/tagtree_upload_case.rb +20 -2
- data/lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb +14 -7
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/diff/as_update.rb +0 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/diffs/stages/diff_sortable/for_archive.rb +0 -1
- data/lib/eco/api/usecases/graphql/helpers/location/command/end_points/optimizations.rb +64 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/end_points.rb +96 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/input_unit_response.rb +69 -0
- data/lib/eco/api/usecases/graphql/helpers/location/command/result.rb +11 -10
- data/lib/eco/api/usecases/graphql/helpers/location/command/results.rb +120 -63
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +26 -26
- data/lib/eco/api/usecases/graphql/samples/location/command/dsl.rb +195 -37
- data/lib/eco/api/usecases/graphql/samples/location/command/results.rb +45 -13
- data/lib/eco/api/usecases/graphql/samples/location/command/service/tree_update.rb +0 -51
- data/lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb +6 -14
- data/lib/eco/api/usecases/graphql/samples/location/command.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb +4 -1
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb +6 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/tree_to_list/converter/input.rb +1 -0
- data/lib/eco/api/usecases/lib/error_handling.rb +1 -1
- data/lib/eco/api/usecases/ooze_samples/helpers/creatable.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/helpers/rescuable.rb +1 -0
- data/lib/eco/data/hashes/array_diff.rb +14 -4
- data/lib/eco/data/locations/node_base/csv_convert.rb +9 -1
- data/lib/eco/data/locations/node_diff/nodes_diff.rb +6 -0
- data/lib/eco/version.rb +1 -1
- metadata +9 -7
- data/lib/eco/api/usecases/graphql/helpers/location/command/optimizations.rb +0 -84
@@ -1,63 +1,133 @@
|
|
1
1
|
module Eco::API::UseCases::GraphQL::Helpers::Location::Command
|
2
|
+
# Final ressults of the full run.
|
2
3
|
class Results
|
3
|
-
|
4
|
+
attr_accessor :draft
|
4
5
|
|
5
|
-
def
|
6
|
-
|
7
|
-
@response = response
|
6
|
+
def draft_id
|
7
|
+
draft&.id
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
msg << " * Errored: #{errored.count} #{first_err_str}\n" if errored?
|
13
|
-
msg << " * Applied: #{errored.count} #{last_okay_str}\n" if some_applied?
|
14
|
-
msg << " * Pending: #{pending.count}\n" if some_pending?
|
15
|
-
msg
|
10
|
+
def parent_structure
|
11
|
+
draft&.parent_structure
|
16
12
|
end
|
17
13
|
|
18
|
-
#
|
19
|
-
def
|
20
|
-
|
14
|
+
# @note target parent structure id
|
15
|
+
def structure_id
|
16
|
+
draft&.structure_id
|
21
17
|
end
|
22
18
|
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# end
|
19
|
+
# @note the result of the draft
|
20
|
+
def structure
|
21
|
+
draft&.structure
|
22
|
+
end
|
28
23
|
|
29
|
-
#
|
30
|
-
def
|
31
|
-
response
|
24
|
+
# @note it receives the final `results` response (when the draft gets published)
|
25
|
+
def final_response(response = nil)
|
26
|
+
return @response if response.nil?
|
27
|
+
|
28
|
+
@response = response
|
29
|
+
end
|
30
|
+
|
31
|
+
def final_response?
|
32
|
+
!final_response.nil?
|
32
33
|
end
|
33
34
|
|
35
|
+
# @note it only accounts for the errors of the final publishing of the draft.
|
34
36
|
def error?
|
35
|
-
|
37
|
+
return false unless final_response
|
38
|
+
|
39
|
+
final_response.error?
|
36
40
|
end
|
37
41
|
|
38
42
|
def success?
|
39
|
-
!error?
|
43
|
+
!error?
|
44
|
+
end
|
45
|
+
|
46
|
+
def applied_commands(with_id_change: false)
|
47
|
+
results.select(&:applied?).then do |applied|
|
48
|
+
next applied unless with_id_change
|
49
|
+
|
50
|
+
applied.select do |result|
|
51
|
+
next false unless (command = result.command_result_data)
|
52
|
+
|
53
|
+
command.keys.include?(:newId)
|
54
|
+
end
|
55
|
+
end
|
40
56
|
end
|
41
57
|
|
42
58
|
def results
|
43
|
-
|
59
|
+
return [] unless final_response
|
60
|
+
|
61
|
+
@results ||= input_commands.zip(command_results).each_with_object([]) do |(i, r), results|
|
44
62
|
results << Result.new(i, r)
|
45
63
|
end
|
46
64
|
end
|
47
65
|
|
66
|
+
# @note this captures the latest draft
|
67
|
+
def add_response(key, input_unit_response)
|
68
|
+
self[key] << input_unit_response
|
69
|
+
input_unit_response.tap do |iur|
|
70
|
+
next if final_response
|
71
|
+
|
72
|
+
self.draft = iur.draft
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def[](key)
|
77
|
+
responses[key] ||= []
|
78
|
+
end
|
79
|
+
|
80
|
+
def responses
|
81
|
+
@responses ||= {}
|
82
|
+
end
|
83
|
+
|
84
|
+
def keys
|
85
|
+
responses.keys
|
86
|
+
end
|
87
|
+
|
48
88
|
def count
|
49
|
-
|
89
|
+
responses.values.flatten.count
|
50
90
|
end
|
51
91
|
|
52
|
-
def
|
53
|
-
|
92
|
+
def input_commands
|
93
|
+
keys.each_with_object([]) do |key, commands|
|
94
|
+
self[key].each do |input|
|
95
|
+
next unless input.is_a?(InputUnitResponse)
|
96
|
+
|
97
|
+
commands.concat(input.commands)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def command_results(response = final_response)
|
103
|
+
response = final_response(response)
|
104
|
+
return [] unless response
|
105
|
+
|
106
|
+
response.results || []
|
107
|
+
end
|
108
|
+
|
109
|
+
def stats
|
110
|
+
msg = ''
|
111
|
+
msg << " * Errored: #{errored.count} #{first_err_str}\n" if errored?
|
112
|
+
msg << " * Applied: #{applied.count} #{last_okay_str}\n" if some_applied?
|
113
|
+
msg << " * Pending: #{pending.count}\n" if some_pending?
|
114
|
+
msg
|
54
115
|
end
|
55
116
|
|
56
|
-
|
57
|
-
|
117
|
+
# Overal errors (i.e. ID clashes between different structures)
|
118
|
+
def error
|
119
|
+
response&.error
|
58
120
|
end
|
59
121
|
|
60
|
-
def
|
122
|
+
# def input_result(input)
|
123
|
+
# results_by_input[input]
|
124
|
+
# end
|
125
|
+
|
126
|
+
# def input_idx(input)
|
127
|
+
# results.index(input_result(input))
|
128
|
+
# end
|
129
|
+
|
130
|
+
def result_idx(result)
|
61
131
|
results.index(result)
|
62
132
|
end
|
63
133
|
|
@@ -65,24 +135,28 @@ module Eco::API::UseCases::GraphQL::Helpers::Location::Command
|
|
65
135
|
@errored ||= results.select(&:error?)
|
66
136
|
end
|
67
137
|
|
138
|
+
def applied
|
139
|
+
@applied ||= results.select(&:applied?)
|
140
|
+
end
|
141
|
+
|
142
|
+
def pending
|
143
|
+
@pending ||= results.select(&:pending?)
|
144
|
+
end
|
145
|
+
|
68
146
|
def errored?
|
69
147
|
errored.any?
|
70
148
|
end
|
71
149
|
|
150
|
+
def applied?
|
151
|
+
results.all?(&:applied?)
|
152
|
+
end
|
153
|
+
|
72
154
|
def first_errored
|
73
155
|
errored.first
|
74
156
|
end
|
75
157
|
|
76
158
|
def first_errored_idx
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
def applied
|
81
|
-
@applied ||= results.select(&:applied?)
|
82
|
-
end
|
83
|
-
|
84
|
-
def applied?
|
85
|
-
results.all?(&:applied?)
|
159
|
+
result_idx(first_errored)
|
86
160
|
end
|
87
161
|
|
88
162
|
def some_applied?
|
@@ -94,11 +168,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location::Command
|
|
94
168
|
end
|
95
169
|
|
96
170
|
def last_applied_idx
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
def pending
|
101
|
-
@pending ||= results.select(&:pending?)
|
171
|
+
result_idx(last_applied)
|
102
172
|
end
|
103
173
|
|
104
174
|
def some_pending?
|
@@ -107,34 +177,21 @@ module Eco::API::UseCases::GraphQL::Helpers::Location::Command
|
|
107
177
|
|
108
178
|
private
|
109
179
|
|
110
|
-
def results_by_input
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
def input_commands
|
117
|
-
input[:commands]
|
118
|
-
end
|
119
|
-
|
120
|
-
def response_results
|
121
|
-
response&.results || []
|
122
|
-
end
|
180
|
+
# def results_by_input
|
181
|
+
# @results_by_input ||= results.each_with_object({}) do |res, h|
|
182
|
+
# h[res.input] = res
|
183
|
+
# end
|
184
|
+
# end
|
123
185
|
|
124
186
|
# First error is relevant only if request was NOT forced to continue.
|
125
187
|
def first_err_str
|
126
|
-
|
127
|
-
|
128
|
-
pre_str = 'stopped on node'
|
129
|
-
pre_str = 'first error' unless force?
|
188
|
+
pre_str = 'first error'
|
130
189
|
|
131
190
|
"(#{pre_str}: '#{first_errored&.node_id}' - idx: #{first_errored_idx})"
|
132
191
|
end
|
133
192
|
|
134
193
|
# Last successfully applied is relevant only if request was NOT forced to continue.
|
135
194
|
def last_okay_str
|
136
|
-
return '' if force?
|
137
|
-
|
138
195
|
"(last node done: '#{last_applied&.node_id}' - idx: #{last_applied_idx})"
|
139
196
|
end
|
140
197
|
end
|
@@ -3,25 +3,10 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
|
|
3
3
|
include Eco::Language::AuxiliarLogger
|
4
4
|
include Eco::API::UseCases::GraphQL::Helpers::Location::Base
|
5
5
|
|
6
|
-
require_relative 'command/
|
7
|
-
include Eco::API::UseCases::GraphQL::Helpers::Location::Command::
|
8
|
-
|
9
|
-
# Actual GraphQL request
|
10
|
-
def apply_commands(input, &block)
|
11
|
-
graphql.locationStructure.applyCommands(input: input, &block)
|
12
|
-
end
|
13
|
-
|
14
|
-
# With given the commands, it generates the input of the endpoint mutation.
|
15
|
-
# @param commands [Array<Hash>]
|
16
|
-
def input(commands, force_continue: force_continue?)
|
17
|
-
{
|
18
|
-
clientMutationId: '',
|
19
|
-
id: target_structure_id,
|
20
|
-
force: force_continue,
|
21
|
-
commands: commands
|
22
|
-
}
|
23
|
-
end
|
6
|
+
require_relative 'command/end_points'
|
7
|
+
include Eco::API::UseCases::GraphQL::Helpers::Location::Command::EndPoints
|
24
8
|
|
9
|
+
# @note it does the API call.
|
25
10
|
# @param track_tree_mode [Symbol] when should updates happen
|
26
11
|
# @return see #with_sliced_input
|
27
12
|
def sliced_batches(
|
@@ -46,17 +31,31 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
|
|
46
31
|
msg << "with #{count} commands (done #{done} of #{total})..."
|
47
32
|
log(:info) { msg }
|
48
33
|
|
49
|
-
response = nil
|
50
34
|
unless simulate? && !options.dig(:requests, :backup)
|
51
|
-
backup(
|
35
|
+
backup(
|
36
|
+
sliced_input,
|
37
|
+
type: "tree_update_#{desc}_request_#{page}_of_#{pages}"
|
38
|
+
)
|
52
39
|
end
|
53
40
|
|
54
|
-
if simulate?
|
55
|
-
log(:info) {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
41
|
+
if simulate? && page < 3
|
42
|
+
log(:info) {
|
43
|
+
JSON.pretty_generate(sliced_input)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# fetch structure? (by using default, when curr_block == nil)
|
48
|
+
response = apply_commands(
|
49
|
+
sliced_input,
|
50
|
+
final: (page == pages),
|
51
|
+
track_tree_mode: track_tree_mode
|
52
|
+
)
|
53
|
+
|
54
|
+
unless simulate?
|
55
|
+
backup(
|
56
|
+
response,
|
57
|
+
type: "tree_update_#{desc}_response_#{page}_of_#{pages}"
|
58
|
+
)
|
60
59
|
end
|
61
60
|
|
62
61
|
done += count
|
@@ -88,6 +87,7 @@ module Eco::API::UseCases::GraphQL::Helpers::Location
|
|
88
87
|
end
|
89
88
|
|
90
89
|
require_relative 'command/result'
|
90
|
+
require_relative 'command/input_unit_response'
|
91
91
|
require_relative 'command/results'
|
92
92
|
require_relative 'command/diff'
|
93
93
|
require_relative 'command/diffs'
|
@@ -1,9 +1,51 @@
|
|
1
1
|
class Eco::API::UseCases::GraphQL::Samples::Location
|
2
2
|
module Command::DSL
|
3
|
+
include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff
|
3
4
|
include Eco::API::UseCases::GraphQL::Helpers::Location::Command
|
4
5
|
include Eco::API::UseCases::GraphQL::Samples::Location::Command::TrackChangedIds
|
5
6
|
include Eco::API::UseCases::GraphQL::Samples::Location::Command::Results
|
6
7
|
|
8
|
+
def print_diff_details?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
# Default tree tacking behaviour
|
13
|
+
# @note
|
14
|
+
# 1. This aims to optimize the time run
|
15
|
+
# 2. Based on update stage, there are differentiated tracking needs
|
16
|
+
# @note Available options are:
|
17
|
+
# - :per_request -> on each request
|
18
|
+
# - :per_batch -> at the end of each batch / stage (on last page)
|
19
|
+
# - :once -> only when the script starts to run
|
20
|
+
# @return [Symbol] the tracking mode
|
21
|
+
def batch_tree_track_mode(stage)
|
22
|
+
case stage
|
23
|
+
when :unarchive, :archive
|
24
|
+
:once
|
25
|
+
when :id, :id_name
|
26
|
+
:per_request
|
27
|
+
when :insert, :move
|
28
|
+
:per_batch
|
29
|
+
else
|
30
|
+
default_tree_tracking_mode
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# With given the commands, it generates the input of the endpoint mutation.
|
35
|
+
# @param commands [Array<Hash>]
|
36
|
+
def input(commands, force_continue: force_continue?)
|
37
|
+
return unless (commands || []).any?
|
38
|
+
|
39
|
+
results.draft ||= create_draft(current_tree.id).draft
|
40
|
+
|
41
|
+
{
|
42
|
+
clientMutationId: '',
|
43
|
+
id: results.draft_id,
|
44
|
+
commands: commands
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# @note this method should be overriden/re-implemented
|
7
49
|
# @example of implementation:
|
8
50
|
# def inputs(command_types, force_continue: force_continue?)
|
9
51
|
# {}.tap do |sequence|
|
@@ -16,14 +58,27 @@ class Eco::API::UseCases::GraphQL::Samples::Location
|
|
16
58
|
# end
|
17
59
|
# end
|
18
60
|
# end
|
19
|
-
def inputs(
|
20
|
-
|
21
|
-
|
22
|
-
|
61
|
+
def inputs(nodes_diff = comparer, force_continue: force_continue?)
|
62
|
+
{}.tap do |sequence|
|
63
|
+
unless nodes_diff && nodes_diff.respond_to?(:commands)
|
64
|
+
msg = "You should implement this method in your child class.\n"
|
65
|
+
msg << "Which should yield the input Hash and the stage or descriptor.\n"
|
66
|
+
msg << "Or you should provide the `nodes_diff` object."
|
67
|
+
raise Eco::API::UseCases::GraphQL::Base::NotImplementedMethod, msg
|
68
|
+
end
|
69
|
+
|
70
|
+
nodes_diff.commands do |comms, stage|
|
71
|
+
sequence[stage] = input(comms, force_continue: force_continue)
|
72
|
+
end
|
73
|
+
end.tap do |sequence|
|
74
|
+
sequence.each do |stage, input|
|
75
|
+
yield(input, stage) if block_given?
|
76
|
+
end
|
77
|
+
end
|
23
78
|
end
|
24
79
|
|
25
|
-
#
|
26
|
-
def process
|
80
|
+
# MAIN PROCESSOR
|
81
|
+
def process
|
27
82
|
self.error = false
|
28
83
|
|
29
84
|
with_error_handling do
|
@@ -32,49 +87,152 @@ class Eco::API::UseCases::GraphQL::Samples::Location
|
|
32
87
|
# this may trigger a backup of the tagtree
|
33
88
|
self.current_tree ||= live_tree
|
34
89
|
|
35
|
-
inputs(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# yields the result of each batch
|
41
|
-
sliced_batches(input, desc: stage, track_tree_mode: track_mode) do |sliced_input, response, page, pages, done, total| # rubocop:disable Metrics/ParameterLists, Layout/LineLength
|
42
|
-
track_current_tree(response&.structure)
|
43
|
-
|
44
|
-
results[stage] << (page_results = request_results_class.new(sliced_input, response))
|
45
|
-
update_tags_remap_table(page_results, stage, current_tree)
|
90
|
+
inputs(
|
91
|
+
force_continue: force_continue?
|
92
|
+
) do |input, stage|
|
93
|
+
next unless input
|
46
94
|
|
47
|
-
|
48
|
-
|
49
|
-
|
95
|
+
sliced_batches(
|
96
|
+
input,
|
97
|
+
desc: stage,
|
98
|
+
track_tree_mode: batch_tree_track_mode(stage),
|
99
|
+
&results_tracking_block(stage: stage)
|
100
|
+
)
|
50
101
|
|
51
|
-
break if error
|
102
|
+
break if error?
|
52
103
|
rescue StandardError => err
|
53
104
|
log(:error) { err.patch_full_message }
|
54
105
|
raise
|
55
106
|
end
|
56
107
|
end
|
57
108
|
ensure
|
58
|
-
rescued {
|
59
|
-
rescued {
|
109
|
+
rescued { rearchive } unless exception
|
110
|
+
rescued { delete_or_publish_draft }
|
111
|
+
rescued { manage_remaps_table }
|
60
112
|
end
|
61
113
|
end
|
62
114
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
115
|
+
def results_tracking_block(stage:)
|
116
|
+
proc do |sliced_input, response, page, pages, done, total|
|
117
|
+
# yields the result of each batch
|
118
|
+
|
119
|
+
input_response = input_unit_response_class.new(
|
120
|
+
sliced_input,
|
121
|
+
response
|
122
|
+
)
|
123
|
+
|
124
|
+
results.add_response(
|
125
|
+
stage,
|
126
|
+
input_response
|
127
|
+
)
|
128
|
+
|
129
|
+
# @todo: might need to set the name and the id by treeifying here.
|
130
|
+
# Alternatively, add named arguments id and name.
|
131
|
+
track_current_tree(results.structure)
|
132
|
+
|
133
|
+
# early detection of errors
|
134
|
+
self.error ||= page_errors?(
|
135
|
+
input_response,
|
136
|
+
page,
|
137
|
+
pages,
|
138
|
+
done,
|
139
|
+
total,
|
140
|
+
stage: stage
|
141
|
+
)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
# Work with adapted diff builders.
|
148
|
+
def nodes_diff_class
|
149
|
+
Eco::API::UseCases::GraphQL::Helpers::Location::Command::Diffs
|
150
|
+
end
|
151
|
+
|
152
|
+
# Before closing, run RE-ARCHIVE: those that where unarchived via archivedToken
|
153
|
+
# that should remain archived.
|
154
|
+
# @note this is an additional necessary step
|
155
|
+
def rearchive
|
156
|
+
return if exception?
|
157
|
+
return unless rearchive_comparer.respond_to?(:stage_commands)
|
158
|
+
return unless rearchive_diffs.any?
|
159
|
+
|
160
|
+
rearchive_commands = rearchive_comparer.stage_commands(:archive)
|
161
|
+
return unless rearchive_commands.any?
|
162
|
+
|
163
|
+
results.draft ||= create_draft(current_tree.id).draft
|
164
|
+
|
165
|
+
stage = :rearchive
|
166
|
+
|
167
|
+
rearchive_comparer.tap do
|
168
|
+
archive_input = input(
|
169
|
+
rearchive_commands,
|
170
|
+
force_continue: true
|
171
|
+
)
|
172
|
+
|
173
|
+
sliced_batches(
|
174
|
+
archive_input,
|
175
|
+
desc: stage,
|
176
|
+
track_tree_mode: :once,
|
177
|
+
&results_tracking_block(stage: stage)
|
178
|
+
)
|
179
|
+
rescue StandardError => err
|
180
|
+
log(:error) { err.patch_full_message }
|
181
|
+
raise
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def rearchive_comparer
|
186
|
+
@rearchive_comparer ||= nodes_diff_class.new(
|
187
|
+
as_nodes_json(current_tree), # hash_list(current_tree),
|
188
|
+
file_nodes_list,
|
189
|
+
original_tree: current_tree,
|
190
|
+
logger: logger
|
191
|
+
)
|
192
|
+
end
|
193
|
+
alias_method :rearchive_diffs, :rearchive_comparer
|
194
|
+
|
195
|
+
def delete_or_publish_draft
|
196
|
+
return unless results.draft_id
|
197
|
+
|
198
|
+
if simulate? || error? || exception?
|
199
|
+
delete = true
|
200
|
+
|
201
|
+
if simulate?
|
202
|
+
delete = false
|
203
|
+
should_delete? { delete = true}
|
204
|
+
end
|
205
|
+
|
206
|
+
delete_draft(results.draft_id) if delete
|
76
207
|
else
|
77
|
-
|
208
|
+
results.final_response(
|
209
|
+
publish_draft(results.draft_id)
|
210
|
+
)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def should_delete?
|
215
|
+
session.prompt_user(
|
216
|
+
'Should delete temporary draft? (Y/n):',
|
217
|
+
default: 'Y',
|
218
|
+
timeout: 5
|
219
|
+
) do |response|
|
220
|
+
next unless response.upcase.start_with?('Y')
|
221
|
+
|
222
|
+
yield
|
78
223
|
end
|
79
224
|
end
|
225
|
+
|
226
|
+
def manage_remaps_table
|
227
|
+
return unless results.final_response?
|
228
|
+
|
229
|
+
rescued do
|
230
|
+
results.applied_commands(with_id_change: true) do |result|
|
231
|
+
update_tags_remap_table(result.command)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
rescued { self.tags_remap_csv_file = generate_tags_remap_csv }
|
236
|
+
rescued { close_handling_tags_remap_csv }
|
237
|
+
end
|
80
238
|
end
|
@@ -5,46 +5,78 @@ class Eco::API::UseCases::GraphQL::Samples::Location
|
|
5
5
|
|
6
6
|
attr_accessor :error
|
7
7
|
|
8
|
-
def
|
8
|
+
def error?
|
9
|
+
!!error
|
10
|
+
end
|
11
|
+
|
12
|
+
def input_unit_response_class
|
13
|
+
Eco::API::UseCases::GraphQL::Helpers::Location::Command::InputUnitResponse
|
14
|
+
end
|
15
|
+
|
16
|
+
def run_results_class
|
9
17
|
Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results
|
10
18
|
end
|
11
19
|
|
12
20
|
# Capture results
|
13
21
|
def results
|
14
|
-
@results ||=
|
22
|
+
@results ||= run_results_class.new
|
15
23
|
end
|
16
24
|
|
17
25
|
# Errors tracking/logging.
|
18
26
|
# @note it gives feedback on where an error has occurred.
|
19
|
-
# @param
|
27
|
+
# @param input_unit_response [Eco::API::UseCases::GraphQL::Helpers::Locations::Commands::CommandResults]
|
20
28
|
# @param stage [Symbol] used when we launch an update in different phases (i.e. rename, move, etc.)
|
21
29
|
# @return [Boolean] whether or not there was an error
|
22
|
-
def page_errors?(
|
23
|
-
msg = "Expecting CommandResults object. Given: #{
|
24
|
-
raise msg unless
|
30
|
+
def page_errors?(input_unit_response, page, pages, done, total, stage: nil)
|
31
|
+
msg = "Expecting CommandResults object. Given: #{input_unit_response.class}"
|
32
|
+
raise msg unless input_unit_response.is_a?(input_unit_response_class)
|
25
33
|
|
26
34
|
stage_str = stage ? "'#{stage}' " : ''
|
27
35
|
fingerprint = "#{stage_str}#{page} (of #{pages})"
|
28
|
-
errored = false
|
29
36
|
|
30
|
-
if
|
37
|
+
if (errored = input_unit_response.error?)
|
38
|
+
log(:error) {
|
39
|
+
msg = "Error on #{fingerprint}: "
|
40
|
+
msg << JSON.pretty_generate(input_unit_response.error_doc)
|
41
|
+
msg
|
42
|
+
}
|
43
|
+
else
|
44
|
+
log(:info) {
|
45
|
+
"Success on #{fingerprint}: #{done} (of #{total}) commands added!"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
errored
|
50
|
+
end
|
51
|
+
|
52
|
+
def result_errors?
|
53
|
+
errored = false
|
54
|
+
|
55
|
+
if results.error?
|
31
56
|
errored = true
|
32
57
|
log(:error) {
|
33
|
-
"Error on #{fingerprint}:
|
58
|
+
msg = "Error on #{fingerprint}: "
|
59
|
+
msg << JSON.pretty_generate(input_unit_response.error_doc)
|
60
|
+
msg
|
34
61
|
}
|
35
62
|
end
|
36
63
|
|
37
|
-
|
64
|
+
# @todo: intermediate status check on drafts doesn't rely on applied
|
65
|
+
# This is rather to be done at the very end, when publishing the draft.
|
66
|
+
if input_unit_response.applied?
|
38
67
|
log(:info) {
|
39
68
|
"Success on #{fingerprint}: #{done} (of #{total}) commands applied!"
|
40
69
|
}
|
41
|
-
elsif
|
70
|
+
elsif input_unit_response.errored?
|
42
71
|
errored = true
|
43
|
-
msg = "Some command failed on #{fingerprint}:\n
|
72
|
+
msg = "Some command failed on #{fingerprint}:\n"
|
73
|
+
msg << input_unit_response.stats
|
74
|
+
|
44
75
|
unless force_continue?
|
45
|
-
first_errored =
|
76
|
+
first_errored = input_unit_response.first_errored
|
46
77
|
msg << "The error(s) - #{first_errored.error_msg}\n"
|
47
78
|
end
|
79
|
+
|
48
80
|
log(:error) { msg }
|
49
81
|
end
|
50
82
|
|