eco-helpers 1.2.1 → 1.2.2

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: f7f4931954cedd399ca4fc599e4e8b1e1d3f1b4502123f06063160aed254d70c
4
- data.tar.gz: 1fc36250ebe32d93d03e59d06773a55995e831e55317b3e71ed7fc3193d3565a
3
+ metadata.gz: a3ad84afe4b64a3fc6285227c511f07973bad7a2fa30563bba3c961607f06882
4
+ data.tar.gz: 6b5b3b281cb22bf03f344647dbd887263544b77de4bd7b5f0a9e724fa3e74291
5
5
  SHA512:
6
- metadata.gz: b1519bd960047cba719b9ff5556374b4653fde6f96c666a9369b874bf1eaaa24f8737e69ed05f70c770932432e8832c3a69c9042a63e3c9add6ffc35b2c97584
7
- data.tar.gz: 52a15098f25c0ebe4ce696356110d33fd79244a1bf9f2edbcf67a29fe5998a87a95f444adbe5e8a8c403907b8b2e9e08ef12d9bf6aa80ecb7b8cac61984c8e8f
6
+ metadata.gz: 35b1e316a53705127ae555572f1186b037862067387b14482285a46fbf76a2402e43d9ea761712c52f7be39c0a281288c63ecd0672baee605d8cd6b2dcee2d58
7
+ data.tar.gz: 7a28bbd1d45d39ad090812496efe5fc26ee916e5db3a28d27ef1582bce8f48e44e2d4ee900143aa172f9603e893a1a09591b4c3e6991e6cfd731c315e352bb55
@@ -1,5 +1,6 @@
1
1
  require 'ecoportal/api'
2
2
  require_relative 'ecoportal_api/base_model'
3
+ require_relative 'ecoportal_api/external_people'
3
4
  require_relative 'ecoportal_api/external_person'
4
5
  require_relative 'ecoportal_api/internal_person'
5
6
  require_relative 'ecoportal_api/account_preferences'
@@ -0,0 +1,38 @@
1
+ module Ecoportal
2
+ module API
3
+ class V1
4
+ class People
5
+
6
+ def job
7
+ operation = Common::BatchOperation.new("/people", person_class, logger: client.logger)
8
+ yield operation
9
+ # The batch operation is responsible for logging the output
10
+ job_id = create_job(operation)
11
+ status = wait_for_job_completion(job_id)
12
+
13
+ if status&.complete?
14
+ operation.process_response job_result(job_id, operation)
15
+ else
16
+ raise "Job `#{job_id}` not complete. Probably timeout after #{JOB_TIMEOUT + 60} seconds. Current status: #{status}"
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def wait_for_job_completion(job_id)
23
+ # timeout library is evil. So we make poor-man timeout.
24
+ # https://jvns.ca/blog/2015/11/27/why-rubys-timeout-is-dangerous-and-thread-dot-raise-is-terrifying/
25
+ before = Time.now
26
+ while true
27
+ status = job_status(job_id)
28
+ break status if status.complete?
29
+ break status if Time.now >= before + (JOB_TIMEOUT + 60)
30
+ sleep(DELAY_STATUS_CHECK)
31
+ status
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,7 +3,7 @@ module Eco
3
3
  class Session
4
4
  class Batch < Common::Session::BaseSession
5
5
 
6
- DEFAULT_BATCH_BLOCK = 100
6
+ DEFAULT_BATCH_BLOCK = 50
7
7
  VALID_METHODS = [:get, :create, :update, :upsert, :delete]
8
8
 
9
9
  class << self
@@ -25,11 +25,11 @@ module Eco
25
25
  # @param people [Eco::API::Organization::People] people object.
26
26
  # @param session [Eco::API:Session]
27
27
  # @param options [Hash] hash with symbol keys (i.e. behaviour modifiers, cli trackers, filters, etc.)
28
- def initialize(type: nil, input: nil, people: nil, session:, options: {})
28
+ def initialize(type: nil, input: nil, people: nil, session:, options: {}, validate: true)
29
29
  @output = nil
30
30
  self.type = type if type
31
31
 
32
- if self.type
32
+ if self.type && validate
33
33
  validate_args(input: input, people: people, session: session, options: options)
34
34
  end
35
35
 
@@ -54,8 +54,8 @@ module Eco
54
54
 
55
55
  # @see Eco::API::UseCases::BaseIO#initialize
56
56
  # @return [Eco::API::UseCases::BaseIO]
57
- def new(type: self.type, input: self.input, people: self.people, session: self.session, options: self.options)
58
- self.class.new(type: type, input: input, people: people, session: session, options: options)
57
+ def new(type: self.type, input: self.input, people: self.people, session: self.session, options: self.options, validate: true)
58
+ self.class.new(type: type, input: input, people: people, session: session, options: options, validate: validate)
59
59
  end
60
60
 
61
61
  # Helper to build a `Hash` of symbol keys or `Array` with params to do callbacks.
@@ -48,6 +48,9 @@ module Eco
48
48
  if callback = data[:callback]
49
49
  unless usecase
50
50
  # identify usecase
51
+ params = io.params(keyed: true).merge(type: type)
52
+ io = io.new(**params, validate: false)
53
+
51
54
  usecase = callback.call(*io.params)
52
55
  unless usecase.is_a?(Eco::API::UseCases::UseCase)
53
56
  msg = "When adding a usecase, without specifying 'case_name:', "
@@ -83,13 +86,8 @@ module Eco
83
86
 
84
87
  processed = true
85
88
 
86
- params = io.params(keyed: true).merge(type: usecase.type)
87
-
88
- #if (!io.people || io.people.empty?) && io.class.people_required?(type)
89
- # params.merge!(people: core_config.people(io: io))
90
- #end
91
-
92
- io.new(**params)
89
+ params = io.params(keyed: true).merge(type: usecase.type)
90
+ io = io.new(**params)
93
91
 
94
92
  if callback = data[:callback]
95
93
  callback.call(*io.params)
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
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: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -247,6 +247,7 @@ files:
247
247
  - lib/eco/api/common/version_patches/ecoportal_api.rb
248
248
  - lib/eco/api/common/version_patches/ecoportal_api/account_preferences.rb
249
249
  - lib/eco/api/common/version_patches/ecoportal_api/base_model.rb
250
+ - lib/eco/api/common/version_patches/ecoportal_api/external_people.rb
250
251
  - lib/eco/api/common/version_patches/ecoportal_api/external_person.rb
251
252
  - lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
252
253
  - lib/eco/api/common/version_patches/exception.rb