eco-helpers 2.7.14 → 2.7.15
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60cb4783ab857207e6a38039be95b0a72d55f5941b4a752819626fecf17b7a46
|
4
|
+
data.tar.gz: 33918eb84042a1761923126495d7d23b4e2a5f9fade69983fbc7db930630e17b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9efbd5e688cdbc29607dc800625927f9065a3220c4fc1caf5c2f6d37d3bd4a945b9c22d70bcf0f066eeecc2459d45b78edad7e306426ea439ec6469546b8a68d
|
7
|
+
data.tar.gz: 0efb4b6dc04def08db1dc7540d637f316ecf85d46ba1aae85f75d70ba0fad6d365bbbd2711b3f17dd7eef664c0f2192212b455cbd7e601b27a59c4a0a364c0ef
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
-
## [2.7.
|
5
|
+
## [2.7.15] - 2024-06-18
|
6
6
|
|
7
7
|
### Added
|
8
8
|
|
@@ -10,6 +10,12 @@ All notable changes to this project will be documented in this file.
|
|
10
10
|
|
11
11
|
### Fixed
|
12
12
|
|
13
|
+
- `Eco::API::Common::People::EntryFactor` super must be called before
|
14
|
+
|
15
|
+
## [2.7.14] - 2024-06-13
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
13
19
|
- `update_tags_remap_table` to build table on **dry-run** too
|
14
20
|
- See `Eco::API::UseCases::GraphQL::Samples::Location::Command::TrackChangedIds`
|
15
21
|
|
@@ -27,6 +27,7 @@ module Eco
|
|
27
27
|
# @param attr_map [nil, Eco::Data::Mapper] attribute names mapper
|
28
28
|
# to translate external names into internal ones and _vice versa_.
|
29
29
|
def initialize(e, schema:, person_parser: nil, default_parser: nil, attr_map: nil)
|
30
|
+
super(e)
|
30
31
|
msg = "Constructor needs a PersonSchema. Given: #{schema.class}"
|
31
32
|
fatal msg unless schema.is_a?(Ecoportal::API::V1::PersonSchema)
|
32
33
|
|
@@ -35,7 +36,6 @@ module Eco
|
|
35
36
|
|
36
37
|
msg = "Expecting Mapper object. Given: #{attr_map.class}"
|
37
38
|
fatal msg if attr_map && !attr_map.is_a?(Eco::Data::Mapper)
|
38
|
-
super(e)
|
39
39
|
|
40
40
|
@schema = Ecoportal::API::V1::PersonSchema.new(JSON.parse(schema.doc.to_json))
|
41
41
|
@source_person_parser = person_parser
|
@@ -2,9 +2,8 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Session
|
4
4
|
class Batch < Common::Session::BaseSession
|
5
|
-
|
6
5
|
DEFAULT_BATCH_BLOCK = 50
|
7
|
-
VALID_METHODS =
|
6
|
+
VALID_METHODS = %i[get create update upsert delete].freeze
|
8
7
|
|
9
8
|
class << self
|
10
9
|
# @return [Boolean] `true` if the method is supported, `false` otherwise.
|
@@ -25,7 +24,8 @@ module Eco
|
|
25
24
|
# @return [Array<People>] all the people based on `params`
|
26
25
|
def get_people(people = nil, params: {}, silent: false)
|
27
26
|
return launch(people, method: :get, params: params, silent: silent).people if people.is_a?(Enumerable)
|
28
|
-
|
27
|
+
|
28
|
+
get(params: params, silent: silent)
|
29
29
|
end
|
30
30
|
|
31
31
|
# launches a batch of `method` type using `people` and the specified `params`
|
@@ -37,11 +37,11 @@ module Eco
|
|
37
37
|
# @param params [Hash] api request options.
|
38
38
|
# @option params [String] :per_page the number of people included per each batch api request.
|
39
39
|
# @return [Batch::Status] the `status` of this batch launch.
|
40
|
-
def launch(people, method:, params: {}
|
40
|
+
def launch(people, method:, params: {}, silent: false)
|
41
41
|
batch_from(people, method: method, params: params, silent: silent)
|
42
42
|
end
|
43
43
|
|
44
|
-
def search(data, silent: false, params: {})
|
44
|
+
def search(data, silent: false, params: {}) # rubocop:disable Metrics/AbcSize
|
45
45
|
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
|
46
46
|
|
47
47
|
launch(data, method: :get, params: params, silent: silent).tap do |status|
|
@@ -50,36 +50,35 @@ module Eco
|
|
50
50
|
entries = status.queue
|
51
51
|
puts "\n"
|
52
52
|
entries.each_with_index do |entry, i|
|
53
|
-
if (i % 10
|
53
|
+
if (i % 10).zero?
|
54
54
|
percent = i * 100 / entries.length
|
55
55
|
print "Searching: #{percent.round}% (#{i}/#{entries.length} entries)\r"
|
56
56
|
$stdout.flush
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
email = nil
|
61
|
-
case
|
62
|
-
when entry.respond_to?(:email)
|
63
|
-
email = entry.email
|
64
|
-
when entry.respond_to?(:to_h)
|
65
|
-
email = entry.to_h["email"]
|
66
|
-
end
|
59
|
+
next if status.success?(entry)
|
67
60
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
61
|
+
email = nil
|
62
|
+
if entry.respond_to?(:email)
|
63
|
+
email = entry.email
|
64
|
+
elsif entry.respond_to?(:to_h)
|
65
|
+
email = entry.to_h["email"]
|
66
|
+
end
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
68
|
+
people_matching = []
|
69
|
+
email = email.to_s.strip.downcase
|
70
|
+
unless email.empty?
|
71
|
+
people_matching = get(params: params.merge(q: email), silent: silent).select do |person|
|
72
|
+
person.email == email
|
81
73
|
end
|
82
74
|
end
|
75
|
+
|
76
|
+
case people_matching.length
|
77
|
+
when 1
|
78
|
+
status.set_person_match(entry, people_matching.first)
|
79
|
+
when 2..Float::INFINITY
|
80
|
+
status.set_people_match(entry, people_matching)
|
81
|
+
end
|
83
82
|
end
|
84
83
|
end
|
85
84
|
end
|
@@ -87,42 +86,61 @@ module Eco
|
|
87
86
|
private
|
88
87
|
|
89
88
|
def get(params: {}, silent: false)
|
90
|
-
|
89
|
+
msg = "cannot batch get without api connnection, please provide a valid api connection!"
|
90
|
+
fatal msg unless (people_api = api&.people)
|
91
|
+
|
91
92
|
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
|
92
|
-
|
93
|
+
people_api.get_all(params: params, silent: silent)
|
93
94
|
end
|
94
95
|
|
95
|
-
|
96
96
|
def batch_from(data, method:, params: {}, silent: false)
|
97
|
-
fatal "Invalid batch method: #{method}."
|
97
|
+
fatal "Invalid batch method: #{method}." unless self.class.valid_method?(method)
|
98
98
|
return nil if !data || !data.is_a?(Enumerable)
|
99
|
-
|
99
|
+
|
100
|
+
msg = "cannot batch #{method} without api connnection, please provide a valid api connection!"
|
101
|
+
fatal msg unless (people_api = api&.people)
|
100
102
|
|
101
103
|
# param q does not make sense here, even for GET method
|
102
104
|
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
|
103
105
|
per_page = params[:per_page] || DEFAULT_BATCH_BLOCK
|
104
106
|
|
105
|
-
launch_batch(
|
106
|
-
|
107
|
-
|
107
|
+
launch_batch(
|
108
|
+
data,
|
109
|
+
method: method,
|
110
|
+
per_page: per_page,
|
108
111
|
people_api: people_api,
|
109
|
-
silent:
|
112
|
+
silent: silent
|
110
113
|
)
|
111
114
|
end
|
112
115
|
|
113
|
-
def launch_batch(
|
114
|
-
|
116
|
+
def launch_batch( # rubocop:disable Metrics/AbcSize
|
117
|
+
data,
|
118
|
+
method:,
|
119
|
+
status: nil,
|
120
|
+
job_mode: true, # rubocop:disable Lint/UnusedMethodArgument
|
121
|
+
per_page: DEFAULT_BATCH_BLOCK,
|
122
|
+
people_api: api&.people,
|
123
|
+
silent: false
|
124
|
+
)
|
125
|
+
iteration = 1
|
126
|
+
done = 0
|
115
127
|
iterations = (data.length.to_f / per_page).ceil
|
116
128
|
|
117
|
-
status ||= Eco::API::Session::Batch::Status.new(
|
118
|
-
|
129
|
+
status ||= Eco::API::Session::Batch::Status.new(
|
130
|
+
enviro,
|
131
|
+
queue: data,
|
132
|
+
method: method
|
133
|
+
)
|
134
|
+
|
135
|
+
status.tap do
|
119
136
|
start_time = Time.now
|
120
|
-
start_slice = Time.now
|
121
|
-
|
137
|
+
start_slice = Time.now
|
138
|
+
|
139
|
+
pending_for_server_error = data.to_a[0..]
|
122
140
|
data.each_slice(per_page) do |slice|
|
123
141
|
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations},"
|
124
|
-
msg
|
125
|
-
msg
|
142
|
+
msg << " with #{slice.length} entries of #{data.length} -- #{done} done"
|
143
|
+
msg << " (last: #{str_stats(start_slice, slice.length)}; total: #{str_stats(start_time, done)})"
|
126
144
|
logger.info(msg) unless silent
|
127
145
|
|
128
146
|
start_slice = Time.now
|
@@ -130,11 +148,12 @@ module Eco
|
|
130
148
|
people_api.batch(job_mode: false) do |batch|
|
131
149
|
slice.each do |person|
|
132
150
|
batch.public_send(method, person) do |response|
|
133
|
-
faltal("Request with no response") unless
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
151
|
+
faltal("Request with no response") unless response
|
152
|
+
|
153
|
+
next if server_error?(response)
|
154
|
+
|
155
|
+
pending_for_server_error.delete(person)
|
156
|
+
status[person] = response
|
138
157
|
end
|
139
158
|
end
|
140
159
|
end # end batch
|
@@ -148,13 +167,15 @@ module Eco
|
|
148
167
|
unless pending_for_server_error.empty?
|
149
168
|
msg = "Going to re-try #{pending_for_server_error.count} due to server errors"
|
150
169
|
logger.info(msg) unless silent
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
170
|
+
|
171
|
+
launch_batch(
|
172
|
+
pending_for_server_error,
|
173
|
+
status: status,
|
174
|
+
method: method,
|
175
|
+
job_mode: false,
|
176
|
+
per_page: per_page,
|
156
177
|
people_api: people_api,
|
157
|
-
silent:
|
178
|
+
silent: silent
|
158
179
|
)
|
159
180
|
end
|
160
181
|
end
|
@@ -164,24 +185,23 @@ module Eco
|
|
164
185
|
res_status = response.status
|
165
186
|
server_error = !res_status || res_status.server_error?
|
166
187
|
other_error = !server_error && (!res_status.code || res_status.code < 100)
|
167
|
-
no_body = !server_error && !other_error
|
188
|
+
no_body = !server_error && !other_error && !response.body
|
168
189
|
server_error || other_error || no_body
|
169
190
|
end
|
170
191
|
|
171
192
|
def offer_retry_on(error_type, retries_left = 3, &block)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
193
|
+
block.call
|
194
|
+
rescue error_type
|
195
|
+
raise unless retries_left.positive?
|
196
|
+
|
197
|
+
explanation = "Batch TimeOut. You have #{retries_left} retries left."
|
198
|
+
question = " Do you want to retry (y/N)?"
|
199
|
+
|
200
|
+
prompt_user(question, default: "Y", explanation: explanation, timeout: 10) do |response|
|
201
|
+
raise unless response.upcase.start_with?("Y")
|
202
|
+
|
203
|
+
puts "\nOkay... let's retry!"
|
204
|
+
offer_retry_on(error_type, retries_left - 1, &block)
|
185
205
|
end
|
186
206
|
end
|
187
207
|
|
@@ -195,7 +215,6 @@ module Eco
|
|
195
215
|
" -- "
|
196
216
|
end
|
197
217
|
end
|
198
|
-
|
199
218
|
end
|
200
219
|
end
|
201
220
|
end
|
@@ -244,12 +244,12 @@ class Eco::API::UseCases::OozeSamples::RegisterUpdateCase < Eco::API::UseCases::
|
|
244
244
|
end
|
245
245
|
|
246
246
|
def conf_filters
|
247
|
-
|
247
|
+
filters if respond_to?(:filters)
|
248
248
|
[]
|
249
249
|
end
|
250
250
|
|
251
251
|
def conf_search
|
252
|
-
|
252
|
+
search if respond_to?(:search)
|
253
253
|
end
|
254
254
|
|
255
255
|
def register_id
|
data/lib/eco/version.rb
CHANGED