eco-helpers 2.0.4 → 2.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/eco-helpers.gemspec +2 -3
- data/lib/eco/api/common/people/person_entry.rb +9 -3
- data/lib/eco/api/common/people/person_parser.rb +1 -1
- data/lib/eco/api/common/version_patches/ecoportal_api/external_person.rb +2 -2
- data/lib/eco/api/error.rb +2 -2
- data/lib/eco/api/session/batch/errors.rb +64 -62
- data/lib/eco/api/session/batch/job.rb +7 -7
- data/lib/eco/api/session/batch/jobs.rb +1 -1
- data/lib/eco/api/session/batch/jobs_groups.rb +1 -0
- data/lib/eco/api/session/batch/status.rb +3 -1
- data/lib/eco/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75a468069bd29d7dc25347e6da7d4d9faebc52043eba8b4ea1e91f6d383a8690
|
4
|
+
data.tar.gz: dee338f8e23d4608f0d359bd44712377d15723c70730e823c11766f179f4877e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c25c8a37c8fe894c57309e07126251e658846881698d4eec1660bf2a1a6cdc2e09f6b3f94c28434e47e7ea1f70cbf69196d2965d0a45609492867b2b356478
|
7
|
+
data.tar.gz: 98bdbf74599ab4a3ab98ac6c76d068bbcf7871774e3f7315f992dbcb9cc31066ac7d2293b8cbee1bc3019bf94e1b9f78c7fdf02b8751cafb403451be12c8c159
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,45 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [2.0.9] - 2021-03-xx
|
5
|
+
|
6
|
+
### Added
|
7
|
+
### Changed
|
8
|
+
- `Eco::API::Session::Batch:Errors#person_ref` moved to the public method
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
## [2.0.8] - 2021-03-09
|
13
|
+
|
14
|
+
### Added
|
15
|
+
### Changed
|
16
|
+
### Fixed
|
17
|
+
- `Ecoportal::API::V1::Person#identity` adjust behavior
|
18
|
+
|
19
|
+
## [2.0.7] - 2021-03-09
|
20
|
+
|
21
|
+
### Added
|
22
|
+
### Changed
|
23
|
+
### Fixed
|
24
|
+
- `Eco::API::Session::Batch::JobsGroups` and `Eco::API::Session::Batch::Jobs`: when new `Batch::Job`s are creating during launch, they remained unlaunched
|
25
|
+
- this fix makes `#launch` method to iterate until there are no pending
|
26
|
+
|
27
|
+
## [2.0.6] - 2021-03-08
|
28
|
+
|
29
|
+
### Added
|
30
|
+
### Changed
|
31
|
+
- `Eco::API::Session::Batch:Errors` moved some methods to be private
|
32
|
+
### Fixed
|
33
|
+
- `Eco::API::Error` should inherit from `StandardError`, rather than from `Exception`
|
34
|
+
|
35
|
+
## [2.0.5] - 2021-02-24
|
36
|
+
|
37
|
+
### Added
|
38
|
+
### Changed
|
39
|
+
### Fixed
|
40
|
+
- `Eco::API::Common::People::PersonParser#symbol_keys` to use `Array#select`
|
41
|
+
- as `Array#filter` was introduced in ruby `2.5.5`
|
42
|
+
|
4
43
|
## [2.0.4] - 2021-02-23
|
5
44
|
|
6
45
|
### Added
|
data/eco-helpers.gemspec
CHANGED
@@ -30,9 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "yard", ">= 0.9.26", "< 0.10"
|
31
31
|
spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
|
32
32
|
|
33
|
-
spec.add_dependency 'ecoportal-api', '>= 0.8.
|
34
|
-
|
35
|
-
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.3', '< 0.9'
|
33
|
+
spec.add_dependency 'ecoportal-api', '>= 0.8.2', '< 0.9'
|
34
|
+
spec.add_dependency 'ecoportal-api-v2', '>= 0.8.6', '< 0.9'
|
36
35
|
spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
|
37
36
|
spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
|
38
37
|
spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
|
@@ -154,14 +154,20 @@ module Eco
|
|
154
154
|
final_entry["default_tag"]
|
155
155
|
end
|
156
156
|
|
157
|
-
# Provides a reference
|
157
|
+
# Provides a reference to this person entry.
|
158
|
+
# @return [String] string summary of this person identity.
|
159
|
+
def identify
|
160
|
+
str_id = id ? "id: '#{id}'; " : ""
|
161
|
+
"(row: #{idx}) '#{name}' (#{str_id}ext_id: '#{external_id}'; email: '#{email}')"
|
162
|
+
end
|
163
|
+
|
164
|
+
# Provides a reference of this person entry.
|
158
165
|
# @return [String] string summary of this person identity.
|
159
166
|
def to_s(options)
|
160
167
|
options = into_a(options)
|
161
168
|
case
|
162
169
|
when options.include?(:identify)
|
163
|
-
|
164
|
-
"(row: #{idx}) '#{name}' (#{str_id}ext_id: '#{external_id}'; email: '#{email}')"
|
170
|
+
identify
|
165
171
|
else
|
166
172
|
final_entry.each.map do |k, v|
|
167
173
|
"'#{k}': '#{v.to_json}'"
|
@@ -108,7 +108,7 @@ module Eco
|
|
108
108
|
# @note this was introduced to boost virtual fields to treat in different phases of the parsing process
|
109
109
|
# @return [Array<Symbol>] all the parsers defined as Symbol
|
110
110
|
def symbol_keys
|
111
|
-
@parsers.keys.
|
111
|
+
@parsers.keys.select {|k| k.is_a?(Symbol)}
|
112
112
|
end
|
113
113
|
|
114
114
|
# Returns a list of all the internal attributes of the model that have a parser defined & that should be active.
|
data/lib/eco/api/error.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
# To identify api server errors
|
4
|
-
class Error <
|
5
|
-
class UnknownErrorClass <
|
4
|
+
class Error < StandardError
|
5
|
+
class UnknownErrorClass < StandardError
|
6
6
|
def initialize(msg = nil, klass:)
|
7
7
|
msg ||= "Unkown api error class #{klass}"
|
8
8
|
super(msg)
|
@@ -8,6 +8,8 @@ module Eco
|
|
8
8
|
# @attr_reader status [Eco::API::Session::Batch::Status] `batch status` this `Errors` object is associated to.
|
9
9
|
attr_reader :status
|
10
10
|
|
11
|
+
ErrorCache = Struct.new(:type, :err, :entry)
|
12
|
+
|
11
13
|
# @param status [Eco::API::Session::Batch::Status] `batch status` this `Errors` object is associated to.
|
12
14
|
def initialize(status:)
|
13
15
|
"Expected Batch::Status as root. Given: #{status.class}" unless status.is_a?(Eco::API::Session::Batch::Status)
|
@@ -55,29 +57,6 @@ module Eco
|
|
55
57
|
entries.length
|
56
58
|
end
|
57
59
|
|
58
|
-
# Input entries that got **error** response from the _Server_.
|
59
|
-
# @raise [Exception] if there are elements of the final `queue` that did not get response
|
60
|
-
# @note discards those that did not get _response_ from the Server (so those that were not queried)
|
61
|
-
# - please, observe that this can only happen if there were repeated entries in the `source_queue`
|
62
|
-
# @return [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
63
|
-
def entries
|
64
|
-
queue.each_with_index.map do |query, i|
|
65
|
-
unless response = status[i]
|
66
|
-
msg = "Error: query with no response. You might have duplicated entries in your queue.\n"
|
67
|
-
msg += "Queue length: #{queue.length}; Queue elements class: #{queue.first.class}\n"
|
68
|
-
msg += "Query with no response. Person: #{person_ref(query)}\n"
|
69
|
-
queue.map do |entry|
|
70
|
-
if [:id, :external_id, :email].any? {|attr| (v = get_attr(entry, attr)) && v == get_attr(query, attr)}
|
71
|
-
msg += "It could be this peson entry (idx: #{to_index(entry)}): #{person_ref(entry)}\n"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
raise msg
|
75
|
-
end
|
76
|
-
|
77
|
-
response.success?? nil : query
|
78
|
-
end.compact
|
79
|
-
end
|
80
|
-
|
81
60
|
# For all the `entries` with errors generates a `Hash` object
|
82
61
|
# @return [Array<Hash>] where each `Hash` has
|
83
62
|
# 1. `:type` -> the error type
|
@@ -88,11 +67,11 @@ module Eco
|
|
88
67
|
if body = status[entry].body
|
89
68
|
if errs = body["errors"]
|
90
69
|
errs.each do |msg|
|
91
|
-
arr.push(
|
92
|
-
|
93
|
-
|
94
|
-
entry
|
95
|
-
|
70
|
+
arr.push(ErrorCache.new(
|
71
|
+
klass = Eco::API::Error.get_type(msg),
|
72
|
+
klass.new(err_msg: msg, entry: entry, session: session),
|
73
|
+
entry
|
74
|
+
))
|
96
75
|
end
|
97
76
|
end
|
98
77
|
end
|
@@ -103,45 +82,16 @@ module Eco
|
|
103
82
|
# @return [Hash] where each `key` is a `type` **error** and each value is
|
104
83
|
# an `Array` of `entries` that got that error
|
105
84
|
def by_type
|
106
|
-
errors.group_by do |
|
107
|
-
|
85
|
+
errors.group_by do |e|
|
86
|
+
e.type
|
108
87
|
end.transform_values do |arr|
|
109
|
-
arr.map {|
|
88
|
+
arr.map {|e| e.entry}
|
110
89
|
end
|
111
90
|
end
|
112
91
|
# @!endgroup
|
113
92
|
|
114
93
|
# @!group Messaging methods
|
115
94
|
|
116
|
-
# Generates a `String` specifying the error for the entry `key`.
|
117
|
-
# @param key [Integer, Ecoportal::API::V1::Person]
|
118
|
-
# @return [String] the error description.
|
119
|
-
def str(key)
|
120
|
-
msg = ""
|
121
|
-
unless status.success?(key)
|
122
|
-
i = to_index(key)
|
123
|
-
entry = queue.to_a[i]
|
124
|
-
response = status[i]
|
125
|
-
msg = "Error #{response.status}: #{response.body}\n"
|
126
|
-
msg += "-- Failed to batch #{method}. Person: #{person_ref(entry)}"
|
127
|
-
end
|
128
|
-
msg
|
129
|
-
end
|
130
|
-
|
131
|
-
# Sorts the entries that got server error by error `type` and generates the error messages.
|
132
|
-
# @return [Array<String>] the errors messages.
|
133
|
-
def strs
|
134
|
-
by_type.values.flatten(1).each_with_object([]) do |query, msgs|
|
135
|
-
msgs.push(str(query))
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def print_one(key)
|
140
|
-
unless status.success?(key)
|
141
|
-
logger.error(str(key))
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
95
|
def message
|
146
96
|
msgs = strs
|
147
97
|
if msgs.length > 0
|
@@ -161,13 +111,36 @@ module Eco
|
|
161
111
|
end
|
162
112
|
# @!endgroup
|
163
113
|
|
164
|
-
private
|
165
|
-
|
166
114
|
def person_ref(entry)
|
167
115
|
row_str = (row = get_row(entry)) ? "(row: #{row}) " : nil
|
168
116
|
"#{row_str}(id: '#{get_attr(entry, :id)}') '#{get_attr(entry, :name)}' ('#{get_attr(entry, :external_id)}': '#{get_attr(entry, :email)}')"
|
169
117
|
end
|
170
118
|
|
119
|
+
private
|
120
|
+
|
121
|
+
# Input entries that got **error** response from the _Server_.
|
122
|
+
# @raise [Exception] if there are elements of the final `queue` that did not get response
|
123
|
+
# @note discards those that did not get _response_ from the Server (so those that were not queried)
|
124
|
+
# - please, observe that this can only happen if there were repeated entries in the `source_queue`
|
125
|
+
# @return [Array<Hash>, Array<Ecoportal::API::V1::Person>, Array<Ecoportal::API::Internal::Person>]
|
126
|
+
def entries
|
127
|
+
queue.filter.with_index do |query, i|
|
128
|
+
unless response = status[i]
|
129
|
+
msg = "Error: query with no response. You might have duplicated entries in your queue.\n"
|
130
|
+
msg += "Queue length: #{queue.length}; Queue elements class: #{queue.first.class}\n"
|
131
|
+
msg += "Query with no response. Person: #{person_ref(query)}\n"
|
132
|
+
queue.map do |entry|
|
133
|
+
if [:id, :external_id, :email].any? {|attr| (v = get_attr(entry, attr)) && v == get_attr(query, attr)}
|
134
|
+
msg += "It could be this peson entry (idx: #{to_index(entry)}): #{person_ref(entry)}\n"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
raise msg
|
138
|
+
end
|
139
|
+
|
140
|
+
!response.success?
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
171
144
|
def get_attr(entry, attr)
|
172
145
|
if entry.respond_to?(attr.to_sym)
|
173
146
|
entry.public_send(attr.to_sym)
|
@@ -185,6 +158,35 @@ module Eco
|
|
185
158
|
end
|
186
159
|
end
|
187
160
|
|
161
|
+
# Sorts the entries that got server error by error `type` and generates the error messages.
|
162
|
+
# @return [Array<String>] the errors messages.
|
163
|
+
def strs
|
164
|
+
by_type.values.flatten(1).each_with_object([]) do |query, msgs|
|
165
|
+
msgs.push(str(query))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Generates a `String` specifying the error for the entry `key`.
|
170
|
+
# @param key [Integer, Ecoportal::API::V1::Person]
|
171
|
+
# @return [String] the error description.
|
172
|
+
def str(key)
|
173
|
+
msg = ""
|
174
|
+
unless status.success?(key)
|
175
|
+
i = to_index(key)
|
176
|
+
entry = queue.to_a[i]
|
177
|
+
response = status[i]
|
178
|
+
msg = "Error #{response.status}: #{response.body}\n"
|
179
|
+
msg += "-- Failed to batch #{method}. Person: #{person_ref(entry)}"
|
180
|
+
end
|
181
|
+
msg
|
182
|
+
end
|
183
|
+
|
184
|
+
def print_one(key)
|
185
|
+
unless status.success?(key)
|
186
|
+
logger.error(str(key))
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
188
190
|
end
|
189
191
|
end
|
190
192
|
end
|
@@ -212,6 +212,13 @@ module Eco
|
|
212
212
|
|
213
213
|
private
|
214
214
|
|
215
|
+
def subjobs_summary
|
216
|
+
return "" unless subjobs.count > 0
|
217
|
+
[].tap do |msg|
|
218
|
+
subjobs.map {|subjob| msg << subjob.summary}
|
219
|
+
end.join("\n")
|
220
|
+
end
|
221
|
+
|
215
222
|
def as_update(*args)
|
216
223
|
feedback.as_update(*args)
|
217
224
|
end
|
@@ -310,13 +317,6 @@ module Eco
|
|
310
317
|
end
|
311
318
|
end
|
312
319
|
|
313
|
-
def subjobs_summary
|
314
|
-
return "" unless subjobs.count > 0
|
315
|
-
[].tap do |msg|
|
316
|
-
subjobs.map {|subjob| msg << subjob.summary}
|
317
|
-
end.join("\n")
|
318
|
-
end
|
319
|
-
|
320
320
|
end
|
321
321
|
end
|
322
322
|
end
|
@@ -122,7 +122,9 @@ module Eco
|
|
122
122
|
def valid_index(index: nil, entry: nil)
|
123
123
|
index ||= @hash[entry]
|
124
124
|
unless index && index < @queue.length
|
125
|
-
|
125
|
+
msg = "You must provide either the index on the final 'queue' or the original entry object of the batch. "
|
126
|
+
msg += "Given, index=#{index.class}, entry:#{entry.class}"
|
127
|
+
fatal msg
|
126
128
|
end
|
127
129
|
index
|
128
130
|
end
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -116,7 +116,7 @@ dependencies:
|
|
116
116
|
requirements:
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: 0.8.
|
119
|
+
version: 0.8.2
|
120
120
|
- - "<"
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0.9'
|
@@ -126,7 +126,7 @@ dependencies:
|
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 0.8.
|
129
|
+
version: 0.8.2
|
130
130
|
- - "<"
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0.9'
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.8.
|
139
|
+
version: 0.8.6
|
140
140
|
- - "<"
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0.9'
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
requirements:
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.8.
|
149
|
+
version: 0.8.6
|
150
150
|
- - "<"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0.9'
|