eco-helpers 2.0.5 → 2.0.10

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: caef8b4ee689f202db51c1be9ea77c1c2e3b21cf16dcaebdf7fd838a260b5e26
4
- data.tar.gz: ad27f525af9bceff0342e5676f898a9da1dbb486c6aad796f2bb3646ccf5cb68
3
+ metadata.gz: b8ca1a088cf60b7608e9f92da680a631c73228ae92fed33484b5669c480350fb
4
+ data.tar.gz: 6733d55fbdcf24c2766529c275f86f3132f1c3232b4c8d31f34880f9253dbc82
5
5
  SHA512:
6
- metadata.gz: 4780834f301910259cb8958c1277de1972ac710f59f7803d34ed2263dc777c18a7a2503e3d6b36879b131b2625b657832a78a27471b690a5d9da8025d381df9f
7
- data.tar.gz: 28b74a9f5d8fe22aadb053fbed4af2e35e4700a04e87fbfc201bd2336521f04814e25c0cbac7f48426172f4b21a05f8b4e4b551eaaffd4067c49609fce0dac92
6
+ metadata.gz: d1cdc2aacd52c590230fe606b079d91e6f3dea01ddbd8857d48170467bbfd089ffa7081c8630aac93ebae4c6e3b8125a446cd7ddc8a6b290c174e906661b2474
7
+ data.tar.gz: 356ccf7e50d3f0e12f9ad1dde6f1fe7ad4fd13205334f9319cecd45736f110684eb404113512aca4b1d2c49070fe61eb48b1e69c3ae13f423ae8895288ea0d2d
data/CHANGELOG.md CHANGED
@@ -1,6 +1,54 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [2.0.10] - 2021-03-xx
5
+
6
+ ### Added
7
+ - `Eco::API::Common::People::PersonParser`
8
+ - `#defined_attrs`: list of all attribute defined parsers (regardless they belong to the model)
9
+ - `Eco::API::Organization::TagTree` methods
10
+ - `#total_depth` to know the total depth of a tree
11
+ - `#flat?` to know if the tagtree has only 1 level
12
+
13
+ ### Changed
14
+ - `Eco::API::Common::People::PersonParser`
15
+ - Renamed `#all_attrs` to `#all_model_attrs`
16
+ - Ranamed `#defined_attrs` to `#defined_model_attrs`
17
+ - Ranamed `#undefined_attrs` to `#undefined_model_attrs`
18
+
19
+ ### Fixed
20
+
21
+ ## [2.0.9] - 2021-03-19
22
+
23
+ ### Added
24
+ ### Changed
25
+ - `Eco::API::Session::Batch:Errors#person_ref` moved to the public method
26
+
27
+ ### Fixed
28
+
29
+ ## [2.0.8] - 2021-03-09
30
+
31
+ ### Added
32
+ ### Changed
33
+ ### Fixed
34
+ - `Ecoportal::API::V1::Person#identity` adjust behavior
35
+
36
+ ## [2.0.7] - 2021-03-09
37
+
38
+ ### Added
39
+ ### Changed
40
+ ### Fixed
41
+ - `Eco::API::Session::Batch::JobsGroups` and `Eco::API::Session::Batch::Jobs`: when new `Batch::Job`s are creating during launch, they remained unlaunched
42
+ - this fix makes `#launch` method to iterate until there are no pending
43
+
44
+ ## [2.0.6] - 2021-03-08
45
+
46
+ ### Added
47
+ ### Changed
48
+ - `Eco::API::Session::Batch:Errors` moved some methods to be private
49
+ ### Fixed
50
+ - `Eco::API::Error` should inherit from `StandardError`, rather than from `Exception`
51
+
4
52
  ## [2.0.5] - 2021-02-24
5
53
 
6
54
  ### 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.1', '< 0.9'
34
- #spec.add_dependency 'ecoportal-api', '>= 0.7.5', '< 0.8'
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 of this person.
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
- str_id = id ? "id: '#{id}'; " : ""
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}'"
@@ -250,7 +256,7 @@ module Eco
250
256
  # @param mapped_entry [Hash] that with **internal** names but **external** values and types.
251
257
  # @return [Hash] with **external** names, values and types.
252
258
  def _external_serializing(mapped_entry)
253
- target_attrs = @emap.all_attrs | @emap.aliased_attrs
259
+ target_attrs = @emap.all_model_attrs | @emap.aliased_attrs
254
260
  rest_keys = mapped_entry.keys - target_attrs
255
261
  target_attrs -= ["send_invites"]
256
262
  external_entry = target_attrs.each_with_object({}) do |attr, hash|
@@ -6,14 +6,14 @@ module Eco
6
6
  # @attr_reader core_attrs [Array<String>] core attributes that are present in the person entry.
7
7
  # @attr_reader details_attrs [Array<String>] schema details attributes that are present in the person entry.
8
8
  # @attr_reader account_attrs [Array<String>] account attributes that are present in the person entry.
9
- # @attr_reader all_attrs [Array<String>] all the attrs that are present in the person entry.
9
+ # @attr_reader all_model_attrs [Array<String>] all the attrs that are present in the person entry.
10
10
  # @attr_reader internal_attrs [Array<String>] all the internally named attributes that the person entry has.
11
11
  # @attr_reader aliased_attrs [Array<String>] only those internal attributes present in the person entry that have an internal/external name mapping.
12
12
  # @attr_reader direct_attrs [Array<String>] only those internal attributes present in the person entry that do **not** have an internal/external name mapping.
13
13
  class PersonEntryAttributeMapper
14
14
  @@cached_warnings = {}
15
15
 
16
- attr_reader :core_attrs, :details_attrs, :account_attrs, :all_attrs
16
+ attr_reader :core_attrs, :details_attrs, :account_attrs, :all_model_attrs
17
17
  attr_reader :internal_attrs, :aliased_attrs, :direct_attrs
18
18
 
19
19
  # Helper class tied to `PersonEntry` that allows to track which attributes of a person entry are present
@@ -41,14 +41,14 @@ module Eco
41
41
  init_attr_trackers
42
42
  else # SERIALIZING
43
43
  @person = data
44
- @internal_attrs = @person_parser.all_attrs
44
+ @internal_attrs = @person_parser.all_model_attrs
45
45
  @aliased_attrs = @attr_map.list(:internal)
46
46
  end
47
47
 
48
48
  @core_attrs = @person_parser.target_attrs_core(@internal_attrs)
49
49
  @details_attrs = @person_parser.target_attrs_details(@internal_attrs)
50
50
  @account_attrs = @person_parser.target_attrs_account(@internal_attrs)
51
- @all_attrs = @core_attrs | @account_attrs | @details_attrs
51
+ @all_model_attrs = @core_attrs | @account_attrs | @details_attrs
52
52
  end
53
53
 
54
54
  # To know if currently the object is in parse or serialize mode.
@@ -98,7 +98,7 @@ module Eco
98
98
  end
99
99
  end
100
100
 
101
- return nil unless @person_parser.all_attrs.include?(attr)
101
+ return nil unless @person_parser.all_model_attrs.include?(attr)
102
102
  end
103
103
 
104
104
  # Serializing helper also used to do a reverse mapping when parsing:
@@ -146,9 +146,9 @@ module Eco
146
146
  # when parsing:
147
147
  def init_attr_trackers
148
148
  # (def) all internal attributes we can expect
149
- def_all_attrs = @person_parser.all_attrs
149
+ def_all_attrs = @person_parser.all_model_attrs
150
150
  # (def) internal attrs with no aliasing nor parser definition (expected to be direct)
151
- def_unlinked = @person_parser.undefined_attrs.select { |attr| !to_external(attr) }
151
+ def_unlinked = @person_parser.undefined_model_attrs.select { |attr| !to_external(attr) }
152
152
  # (def) those with parser or alias:
153
153
  def_linked = def_all_attrs - def_unlinked
154
154
 
@@ -168,7 +168,7 @@ module Eco
168
168
  # (data) virtual internal attrs (the internal names of those virtual attrs)
169
169
  data_vi_int_aliased = data_vi_ext_alias.map do |attr|
170
170
  # to_internal(attr) can't be used here, becauase virtual fields would get filtered out,
171
- # as they are not recognized by @parser.all_attrs.include?(attr)
171
+ # as they are not recognized by @parser.all_model_attrs.include?(attr)
172
172
  @attr_map.to_internal(attr)
173
173
  end.compact
174
174
 
@@ -7,7 +7,7 @@ module Eco
7
7
  #
8
8
  # @attr_reader schema [Ecoportal::API::V1::PersonSchema, nil] schema of person details that this parser will be based upon.
9
9
  # @attr_reader details_attrs [Array<String>] internal names of schema details attributes.
10
- # @attr_reader all_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
10
+ # @attr_reader all_model_attrs [Array<String>] all the internal name attributes, including _core_, _account_ and _details_.
11
11
  class PersonParser
12
12
  extend Eco::API::Common::ClassAutoLoader
13
13
  autoloads_children_of "Eco::API::Common::Loaders::Parser"
@@ -19,8 +19,7 @@ module Eco
19
19
  FORMAT = [:csv, :xml, :json]
20
20
 
21
21
  attr_reader :schema
22
- attr_reader :details_attrs, :all_attrs
23
- attr_reader :defined_attrs
22
+ attr_reader :details_attrs, :all_model_attrs
24
23
  attr_reader :patch_version
25
24
 
26
25
  # @example Example of usage:
@@ -46,7 +45,7 @@ module Eco
46
45
  @details_attrs = @schema&.fields.map { |fld| fld.alt_id }
47
46
  end
48
47
 
49
- @all_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
48
+ @all_model_attrs = CORE_ATTRS + ACCOUNT_ATTRS + @details_attrs
50
49
  self.class.autoload_children(self)
51
50
  end
52
51
 
@@ -60,6 +59,11 @@ module Eco
60
59
 
61
60
  # @!group Scopping attributes (identifying, presence & active)
62
61
 
62
+ # All the internal name attributes, including _core_, _account_ and _details_.
63
+ def all_attrs(include_defined_parsers: false)
64
+ all_model_attrs | defined_model_attrs
65
+ end
66
+
63
67
  # Scopes `source_attrs` using the _**core** attributes_.
64
68
  # @note use this helper to know which among your attributes are **core** ones.
65
69
  # @param source_attrs [Array<String>]
@@ -93,14 +97,21 @@ module Eco
93
97
  @parsers.keys
94
98
  end
95
99
 
100
+ # Returns a list of all the internal attributes that have a parser defined.
101
+ # @note These attributes do not necessarily belong to the model. They could be virtual attributes
102
+ # @return [Array<String>] list of all attribute defined parsers.
103
+ def defined_attrs
104
+ defined_list - symbol_keys
105
+ end
106
+
96
107
  # Returns a list of all the internal attributes of the model that have a parser defined.
97
108
  # @note
98
109
  # - it excludes any parser that is not in the model, such as type parsers (i.e. `:boolean`, `:multiple`)
99
110
  # - the list is sorted according `CORE_ATTRS` + `ACCOUNT_ATTRS` + schema attrs
100
- # @return [Array<String>] list of all attribute defined parsers.
101
- def defined_attrs
111
+ # @return [Array<String>] list of all attribute defined parsers in the model.
112
+ def defined_model_attrs
102
113
  defined = @parsers.keys
103
- defined = (all_attrs | defined) & defined
114
+ defined = (all_model_attrs | defined) & defined
104
115
  defined - symbol_keys
105
116
  end
106
117
 
@@ -118,7 +129,7 @@ module Eco
118
129
  # @param process [Symbol] either `:parse` or `:serialize`, depending if we want to parse or serialize the `attr`.
119
130
  # @return [Array<String>] list of all attribute defined parsers that should be active for the given `source_data`.
120
131
  def active_attrs(source_data, phase = :any, process: :parse)
121
- defined_attrs.select do |attr|
132
+ defined_model_attrs.select do |attr|
122
133
  if process == :serialize
123
134
  @parsers[attr].serializer_active?(phase)
124
135
  else
@@ -130,8 +141,8 @@ module Eco
130
141
  # Returns a list of all the internal attributes of the model that do **not** have a parser defined.
131
142
  # @note it excludes any parser that is **not** in the model, such as type parsers (i.e. :boolean, :multiple)
132
143
  # @return [Array<String>] list of all attributes without a defined parser.
133
- def undefined_attrs
134
- all_attrs - defined_attrs
144
+ def undefined_model_attrs
145
+ all_model_attrs - defined_model_attrs
135
146
  end
136
147
 
137
148
  # @param attr [String] internal name of an attribute.
@@ -238,7 +249,7 @@ module Eco
238
249
  end
239
250
 
240
251
  def valid_attr?(attr)
241
- attr.is_a?(String) && (!@schema || @all_attrs.include?(attr))
252
+ attr.is_a?(String) && (!@schema || @all_model_attrs.include?(attr))
242
253
  end
243
254
 
244
255
  def valid_type?(attr)
@@ -13,8 +13,8 @@ module Ecoportal
13
13
  original_doc["details"] = JSON.parse(doc["details"])
14
14
  end
15
15
 
16
- def identify
17
- if entry
16
+ def identify(section = :person)
17
+ if entry && section == :entry
18
18
  entry.to_s(:identify)
19
19
  else
20
20
  str_id = id ? "id: '#{id}'; " : ""
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 < Exception
5
- class UnknownErrorClass < Exception
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)
@@ -4,7 +4,7 @@ module Eco
4
4
 
5
5
  # Provides helpers to deal with tagtrees.
6
6
  class TagTree
7
- attr_reader :tag, :nodes
7
+ attr_reader :tag, :nodes, :children_count
8
8
  attr_reader :depth, :path
9
9
  attr_reader :enviro
10
10
 
@@ -37,6 +37,7 @@ module Eco
37
37
 
38
38
  nodes = @source.is_a?(Array) ? @source : @source.dig('nodes') || []
39
39
  @nodes = nodes.map {|cnode| TagTree.new(cnode, depth: @depth + 1, path: @path.dup, enviro: @enviro)}
40
+ @children_count = @nodes.count
40
41
 
41
42
  init_hashes
42
43
  end
@@ -46,6 +47,21 @@ module Eco
46
47
  @has_tags.empty?
47
48
  end
48
49
 
50
+ # @return [Integer] the highest `depth` of all the children.
51
+ def total_depth
52
+ @total_depth ||= if children_count > 0
53
+ deepest_node = nodes.max_by {|node| node.total_depth}
54
+ deepest_node.depth
55
+ else
56
+ depth
57
+ end
58
+ end
59
+
60
+ # @return [Integer] if there's only top level.
61
+ def flat?
62
+ self.total_depth <= 0
63
+ end
64
+
49
65
  # Gets all the tags of the current node tree.
50
66
  # @note
51
67
  # - this will include the upper level tag(s) as well
@@ -147,7 +163,8 @@ module Eco
147
163
  # * take the deepest tag (the one that is further down in the tree)
148
164
  # * if there are different options (several nodes at the same depth):
149
165
  # * take the common node between them (i.e. you have Hamilton and Auckland -> take New Zealand)
150
- # * if there's no common node between them, take the `first` (unless they are at top level of the tree)
166
+ # * if there's no common node between them, take the `first`, unless they are at top level of the tree
167
+ # * to the above, take the `first` also on top level, but only if there's 1 level for the entire tree
151
168
  # @param [Array<String>] values list of tags.
152
169
  # @return [String] default tag.
153
170
  def default_tag(*values)
@@ -169,7 +186,7 @@ module Eco
169
186
  common = nodes.reduce(self.tags.reverse) {|com, cnode| com & cnode.path.reverse}
170
187
  default_tag = common.first if common.length > 0 && depth > 0
171
188
  end
172
- default_tag = nodes.first&.tag if !default_tag && depth > 0
189
+ default_tag = nodes.first&.tag if !default_tag && ( (depth > 0) || flat?)
173
190
  default_tag
174
191
  end
175
192
 
@@ -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
- type: klass = Eco::API::Error.get_type(msg),
93
- err: klass.new(err_msg: msg, entry: entry, session: session),
94
- entry: 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 |h|
107
- h[:type]
85
+ errors.group_by do |e|
86
+ e.type
108
87
  end.transform_values do |arr|
109
- arr.map {|h| h[:entry]}
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
@@ -94,7 +94,7 @@ module Eco
94
94
  callback.call(job, job_status) if callback
95
95
  end
96
96
  end
97
-
97
+ launch(simulate: simulate) if pending?
98
98
  return status
99
99
  end
100
100
 
@@ -96,6 +96,7 @@ module Eco
96
96
  self.class.counter(DELAY_BETWEEN_GROUPS) if !simulate && idx < @order.length - 1
97
97
  end
98
98
  end
99
+ launch(simulate: simulate) if pending?
99
100
  return status
100
101
  end
101
102
 
@@ -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
- fatal "You must provide either the index on the final 'queue' or the original entry object of the batch"
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
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.10"
3
3
  end
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.5
4
+ version: 2.0.10
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.1
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.1
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.3
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.3
149
+ version: 0.8.6
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.9'