eco-helpers 2.1.8 → 2.1.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: 34fabf1bbcb318ac7860992bc5a24a5b27e7941e6976cda455d1e65e274fa16c
4
- data.tar.gz: e44bc288d08d82ce98921f63c978d84e8813883a729e17a718978aab293d9c44
3
+ metadata.gz: 7a10a887a29d2f0e2bbfba835c32c6fb2f35ed6cbbc674ad108ec1da81192d50
4
+ data.tar.gz: afc195b30a643cffaadb8b2b271e5d83d4981d1fed3d4111525ec83279a6f825
5
5
  SHA512:
6
- metadata.gz: a94bc6ca7d5c012dc03491e6e96456d4ae620c4ecfc52023716525caadb4e6683e49de8fe8d56479dc883b4710bef1c2a3b9f51fd4a7d6e7da52e0cf1d15cb50
7
- data.tar.gz: 7ca163e67e3675bf3d0a84b4f11cb57cf25c164b169d418164da94963cfdbdcb5d6cc8b8ae78fb5311e955119190b93d254c715e24a05de73f90974e6ed154dd
6
+ metadata.gz: 303c97a14c92ec6b0f6b0011726f8836a5d3cc2e096afc4fdcf991b3160e771015b4cf642fb781214b256d0119216a44710fbac4daab700c58950a0c01ca9a9d
7
+ data.tar.gz: 52a52c731cd43dbb56dad4910a26ea5e3e1658f919ff78e6e15d7bc57383e03841e0642c12e801585600abc89f9571dad895b66208703402c25e2a252da46b59
data/CHANGELOG.md CHANGED
@@ -1,12 +1,29 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.1.9] - 2022-11-xx
4
+ ## [2.1.11] - 2022-11-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
+ ## [2.1.10] - 2022-11-30
11
+
12
+ ### Fixed
13
+ - `Eco::API::Session::Batch::Errors#errors`
14
+ - include errors with no `error` property in body (i.e. `!response.success?`)
15
+
16
+ ## [2.1.9] - 2022-11-29
17
+
18
+ ### Changed
19
+ - upgrade `ecoportal-api-v2` **gem** dependency
20
+ - upgrade `ecoportal-api-graphql` **gem** dependency
21
+
22
+ ### Fixed
23
+ - `Eco::API::Session::Batch::Job`
24
+ - Ability to skip prefilter of entries with no `id` on `:update`
25
+ - Enhanced error tracking (bug resilience)
26
+
10
27
  ## [2.1.8] - 2022-11-18
11
28
 
12
29
  ### Added
data/eco-helpers.gemspec CHANGED
@@ -31,8 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
32
32
 
33
33
  spec.add_dependency 'ecoportal-api', '>= 0.8.5', '< 0.9'
34
- spec.add_dependency 'ecoportal-api-v2', '>= 0.9.6', '< 0.10'
35
- spec.add_dependency 'ecoportal-api-graphql', '>= 0.1.10', '< 0.2'
34
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.9.7', '< 0.10'
35
+ spec.add_dependency 'ecoportal-api-graphql', '>= 0.1.11', '< 0.2'
36
36
  spec.add_dependency 'aws-sdk-s3', '>= 1.83.0', '< 2'
37
37
  spec.add_dependency 'aws-sdk-ses', '>= 1.36.0', '< 2'
38
38
  spec.add_dependency 'dotenv', '>= 2.7.6', '< 2.8'
data/lib/eco/api/error.rb CHANGED
@@ -76,7 +76,6 @@ module Eco
76
76
  @str_err = "Unknown details field."
77
77
  @match = /details \> (.+?) is an unknown field/
78
78
  end
79
-
80
79
  end
81
80
 
82
81
  class << self
@@ -135,7 +134,6 @@ module Eco
135
134
  @err_msg = err_msg
136
135
  @session = session
137
136
  @entry = entry
138
-
139
137
  super(built_error)
140
138
  end
141
139
 
@@ -84,16 +84,20 @@ module Eco
84
84
  entries.each_with_object([]) do |entry, arr|
85
85
  response = status[entry]
86
86
  if body = response.body
87
+ errs = []
87
88
  if errs = body["errors"] || body["error"]
88
89
  errs = [errs].flatten(1).compact
89
- errs.each do |msg|
90
- arr.push(ErrorCache.new(
91
- klass = Eco::API::Error.get_type(msg),
92
- klass.new(err_msg: msg, entry: entry, session: session),
93
- entry,
94
- response
95
- ))
96
- end
90
+ end
91
+ if errs.empty? && !response.success?
92
+ errs = [body["response"]].flatten(1).compact
93
+ end
94
+ errs.each do |msg|
95
+ arr.push(ErrorCache.new(
96
+ klass = Eco::API::Error.get_type(msg),
97
+ klass.new(err_msg: msg, entry: entry, session: session),
98
+ entry,
99
+ response
100
+ ))
97
101
  end
98
102
  end
99
103
  end
@@ -185,7 +189,6 @@ module Eco
185
189
  logger.error(str(key))
186
190
  end
187
191
  end
188
-
189
192
  end
190
193
  end
191
194
  end
@@ -34,7 +34,10 @@ module Eco
34
34
  # @param type [Symbol] a valid batch operation.
35
35
  # @param usecase [Eco::API::UseCases::UseCase, nil] when provided: `usecase` that generated this `batch job`.
36
36
  # This is necessary to know the `options` used to run the usecase, which could modify the `Batch::Job` behviour.
37
- def initialize(e, name:, type:, sets:, usecase: nil)
37
+ # @param accept_update_with_no_id [Boolean] temporary contingency
38
+ # This parameter has been added due to a bug on server side.
39
+ # An external_id is still required.
40
+ def initialize(e, name:, type:, sets:, usecase: nil, accept_update_with_no_id: false)
38
41
  raise "A name is required to refer a job. Given: #{name}" if !name
39
42
  raise "Type should be one of #{self.class.types}. Given: #{type}" unless self.class.valid_type?(type)
40
43
  raise "Sets should be some of #{self.class.sets}. Given: #{sets}" unless self.class.valid_sets?(sets)
@@ -46,6 +49,7 @@ module Eco
46
49
  @sets = [sets].flatten.compact
47
50
  @usecase = usecase
48
51
  @feedback = Eco::API::Session::Batch::Feedback.new(job: self)
52
+ @accept_update_with_no_id = accept_update_with_no_id
49
53
  reset
50
54
  end
51
55
 
@@ -244,12 +248,18 @@ module Eco
244
248
  # - The contingency above wouldn't be necessary if the server worked perfectly.
245
249
  def processed_queue
246
250
  pre_filtered = @queue.select do |entry|
251
+ by_pass_filter = false
247
252
  if unexisting = entry.new? && !entry.id && type != :create
248
253
  ref = Eco::API::Session::Batch::Feedback.person_ref(entry)
249
- msg = "Job ('#{name}':#{type}): excluded unexisting entry (failed creation): #{ref}"
254
+ msg = "Job ('#{name}':#{type}): "
255
+ if (by_pass_filter = entry.external_id && @accept_update_with_no_id)
256
+ msg << "entry errored on creation (failed creation) but will try with person code: #{ref}"
257
+ else
258
+ msg << "excluded unexisting entry (failed creation): #{ref}"
259
+ end
250
260
  session.logger.warn(msg)
251
261
  end
252
- !unexisting
262
+ !unexisting || by_pass_filter
253
263
  end
254
264
  pre_filtered.each {|e| @callbacks[e].call(e) if @callbacks.key?(e) }
255
265
  apply_policies(api_included(pre_filtered)).select do |e|
@@ -321,9 +331,25 @@ module Eco
321
331
  status.queue.map do |entry|
322
332
  if status.success?(entry)
323
333
  if type == :create && entry.respond_to?(:id=)
324
- entry.id = status[entry].body["id"]
334
+ entry.id = status[entry].body["id"].tap do |id|
335
+ if id.to_s.strip.empty?
336
+ ref = Eco::API::Session::Batch::Feedback.person_ref(entry)
337
+ msg = "Entry has been created but API did not return its 'id': #{ref}"
338
+ if response = status[entry]
339
+ msg << " (Response - status: #{response.status.code}; body: #{response.body.pretty_inspect})"
340
+ end
341
+ logger.error(msg)
342
+ end
343
+ end
344
+ end
345
+ if entry.respond_to?(:consolidate!)
346
+ entry.consolidate!
347
+ if entry.respond_to?(:dirty?) && entry.dirty? && entry.respond_to?(:as_update)
348
+ msg = "After consolidate there's still a dirty model:\n"
349
+ msg << entry.as_update.pretty_inspect
350
+ logger.debug(msg)
351
+ end
325
352
  end
326
- entry.consolidate! if entry.respond_to?(:consolidate!)
327
353
  #else # do not entry.reset! (keep track on changes still)
328
354
  end
329
355
  end
@@ -370,7 +396,6 @@ module Eco
370
396
  subjobs.add(subjob, &block)
371
397
  end
372
398
  end
373
-
374
399
  end
375
400
  end
376
401
  end
@@ -49,9 +49,9 @@ module Eco
49
49
  # - the block should only be passed when creating the job
50
50
  # @param [see @Eco::API::Session::Batch::Jobs#new]
51
51
  # @return [Eco::API::Session::Batch::Job]
52
- def job(name, type: nil, sets: nil, usecase: nil, &block)
52
+ def job(name, type: nil, sets: nil, usecase: nil, accept_update_with_no_id: false, &block)
53
53
  fatal "Can't give a job post-launch callback &block to an already existing job" if exists?(name)
54
- new(name, type: type, sets: sets, usecase: usecase, &block) unless exists?(name)
54
+ new(name, type: type, sets: sets, usecase: usecase, accept_update_with_no_id: accept_update_with_no_id, &block) unless exists?(name)
55
55
  self[name]
56
56
  end
57
57
 
@@ -61,10 +61,10 @@ module Eco
61
61
  # @yieldparam job [Eco::API::Session::Batch::Job] the job we have launched against the server.
62
62
  # @yieldparam status [Eco::API::Session::Batch::Status] the status of the batch job launch.
63
63
  # @return [Eco::API::Session::Batch::Job]
64
- def new(name, type:, sets:, usecase: nil, &block)
64
+ def new(name, type:, sets:, usecase: nil, accept_update_with_no_id: false, &block)
65
65
  fatal "Can't create job named '#{name}' because it already exists." if exists?(name)
66
66
 
67
- Batch::Job.new(enviro, name: name, type: type, sets: sets, usecase: usecase).tap do |job|
67
+ Batch::Job.new(enviro, name: name, type: type, sets: sets, usecase: usecase, accept_update_with_no_id: accept_update_with_no_id).tap do |job|
68
68
  add(job, &block)
69
69
  end
70
70
  end
@@ -251,8 +251,8 @@ module Eco
251
251
  # Shortcut to create a job of certain type within a group
252
252
  # @param [see @Eco::API::Session::Batch::Jobs#new]
253
253
  # @return [Eco::API::Session::Batch::Job]
254
- def new_job(group, name, type, usecase, sets = [:core, :details, :account], &block)
255
- job_group(group).new(name, usecase: usecase, type: type, sets: sets, &block)
254
+ def new_job(group, name, type, usecase, sets = [:core, :details, :account], accept_update_with_no_id = false, &block)
255
+ job_group(group).new(name, usecase: usecase, type: type, sets: sets, accept_update_with_no_id: accept_update_with_no_id, &block)
256
256
  end
257
257
 
258
258
  # @see Eco::API::Session::Batch::JobsGroups#launch
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.1.8"
2
+ VERSION = "2.1.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.1.8
4
+ version: 2.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 0.9.6
139
+ version: 0.9.7
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0.10'
@@ -146,7 +146,7 @@ dependencies:
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 0.9.6
149
+ version: 0.9.7
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.10'
@@ -156,7 +156,7 @@ dependencies:
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 0.1.10
159
+ version: 0.1.11
160
160
  - - "<"
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0.2'
@@ -166,7 +166,7 @@ dependencies:
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: 0.1.10
169
+ version: 0.1.11
170
170
  - - "<"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0.2'