eco-helpers 1.2.2 → 1.3.1

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: a3ad84afe4b64a3fc6285227c511f07973bad7a2fa30563bba3c961607f06882
4
- data.tar.gz: 6b5b3b281cb22bf03f344647dbd887263544b77de4bd7b5f0a9e724fa3e74291
3
+ metadata.gz: adb97e964a09a628b29aa507f3f6d764df82b7c8dbdd568f86245ab05fdfb4bb
4
+ data.tar.gz: 1f09ede76add050f3800d6683717a1ccd8f45e6af46f030e53d24edee74f7273
5
5
  SHA512:
6
- metadata.gz: 35b1e316a53705127ae555572f1186b037862067387b14482285a46fbf76a2402e43d9ea761712c52f7be39c0a281288c63ecd0672baee605d8cd6b2dcee2d58
7
- data.tar.gz: 7a28bbd1d45d39ad090812496efe5fc26ee916e5db3a28d27ef1582bce8f48e44e2d4ee900143aa172f9603e893a1a09591b4c3e6991e6cfd731c315e352bb55
6
+ metadata.gz: c0d9585e4c20c5e9f0f8ca0101789dc9e50e6e08a71297c0376f1c2334abe602fbe24ca5fee178c840c2c52e0ee6a1446c26eee0103a377f29e99fbe9afece46
7
+ data.tar.gz: e3894a74b853858da71ee783f460eed18cbd68dae92a941ea755a687b84c7b27f4899a675c7cb16ecbb83d0eb4105aa8380d8dea3ac64493a7e82f6802a14e37
data/lib/eco/api/error.rb CHANGED
@@ -74,6 +74,10 @@ module Eco
74
74
  def descendants(direct: false)
75
75
  ObjectSpace.each_object(::Class).select do |klass|
76
76
  klass < self
77
+ end.sort do |k1, k2|
78
+ next -1 if k2 < k1
79
+ next 1 if k1 < k2
80
+ 0
77
81
  end.tap do |siblings|
78
82
  if direct
79
83
  siblings.reject! do |si|
@@ -2,9 +2,9 @@ module Eco
2
2
  module API
3
3
  class Error
4
4
  class Handler < Eco::API::UseCases::UseCase
5
- @types = [:transform]
5
+ @types = [:error_handler]
6
6
 
7
- def initialize(name, type: :transform, root:, &block)
7
+ def initialize(name, type: :error_handler, root:, &block)
8
8
  super(name, type: type, root: root, &block)
9
9
  end
10
10
 
@@ -8,7 +8,7 @@ module Eco
8
8
  super(handler)
9
9
  end
10
10
 
11
- def on(klass_err, type: :transform, retry: true, &block)
11
+ def on(klass_err, type: :error_handler, retry: true, &block)
12
12
  Eco::API::Error.validate_err_class(klass_err)
13
13
  raise "Expected block but not given" unless block
14
14
  Eco::API::Error::Handler.new(klass_err, type: type, root: self, &block).tap do |handler|
@@ -56,13 +56,21 @@ module Eco
56
56
  hash = entry.as_json.slice("id", "external_id", "email")
57
57
  else
58
58
  hash = entry.as_update
59
- if entry.details
59
+ #if entry.details
60
+ if hash["details"]
60
61
  if hfields = hash.dig("details", "fields")
61
62
  hfields.each do |fld|
62
63
  fld.merge!("alt_id" => entry.details.get_field(fld["id"]).alt_id)
63
64
  end
64
65
  end
65
66
  end
67
+
68
+ if account = hash["account"]
69
+ if account.keys == ["send_invites"] && !account["send_invites"]
70
+ hash.delete("account")
71
+ hash.delete("id") if hash.keys == ["id"]
72
+ end
73
+ end
66
74
  end
67
75
  end
68
76
  hash || {}
@@ -56,6 +56,20 @@ module Eco
56
56
  @status = nil
57
57
  end
58
58
 
59
+ # Creates an empty `Batch::Job` with same behaviour as the current one
60
+ # @note
61
+ # * this job will not be linked to the `Batch::Jobs` model of the current session
62
+ # * mostly used for error_handlers
63
+ # @return [Eco::API::Session::Batch::Job]
64
+ def dup(name = "ad-hoc:job-from:#{self.name}", usecase: nil)
65
+ self.class.new(enviro, name: name, type: type, sets: sets, usecase: usecase)
66
+ end
67
+
68
+ # @return [Boolean] `true` if the current batch job is a result of an error_handler
69
+ def error_handler?
70
+ usecase? && usecase.is_a?(Eco::API::Error::Handler)
71
+ end
72
+
59
73
  # @return [Boolean] was this `batch job` generated by a `usecase`? (`Eco::API::UseCases::UseCase`)
60
74
  def usecase?
61
75
  !!usecase
@@ -251,13 +265,15 @@ module Eco
251
265
  #else # do not entry.reset! (keep track on changes still)
252
266
  end
253
267
  end
254
- # launch_error handlers
268
+ # launch error_handlers
255
269
  handlers = session.config.error_handlers
256
- if status.errors.any? && !handlers.empty?
270
+ if status.errors.any? && !handlers.empty? && !error_handler?
257
271
  err_types = status.errors.by_type
258
272
  handlers.each do |handler|
259
273
  if entries = err_types[handler.name]
260
- handler.launch(people: people(entries), session: session, options: options)
274
+ handler_job = self.dup("#{self.name} => #{handler.name}", usecase: handler)
275
+ handler.launch(people: people(entries), session: session, options: options, job: handler_job)
276
+ handler_job.launch(simulate: simulate)
261
277
  end
262
278
  end
263
279
  end
@@ -12,7 +12,7 @@ module Eco
12
12
  end
13
13
  end
14
14
 
15
- @types = [:import, :filter, :transform, :sync, :export, :other]
15
+ @types = [:import, :filter, :transform, :sync, :error_handler, :export, :other]
16
16
 
17
17
  class << self
18
18
  attr_reader :types
@@ -11,7 +11,7 @@ module Eco
11
11
  end
12
12
 
13
13
  def people_required?(type)
14
- !valid_type?(type) || [:filter, :transform, :sync, :export].include?(type)
14
+ !valid_type?(type) || [:filter, :transform, :sync, :error_handler, :export].include?(type)
15
15
  end
16
16
 
17
17
  end
@@ -54,8 +54,16 @@ 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, validate: true)
58
- self.class.new(type: type, input: input, people: people, session: session, options: options, validate: validate)
57
+ def new(**kargs)
58
+ default = {
59
+ type: self.type,
60
+ input: self.input,
61
+ people: self.people,
62
+ session: self.session,
63
+ options: self.options,
64
+ validate: true
65
+ }.merge(kargs)
66
+ self.class.new(**default.merge(kargs))
59
67
  end
60
68
 
61
69
  # Helper to build a `Hash` of symbol keys or `Array` with params to do callbacks.
@@ -40,7 +40,7 @@ module Eco
40
40
  kargs = params.merge(kargs).merge(usecase: self)
41
41
 
42
42
  UseCaseIO.new(**kargs).tap do |uio|
43
- @options = uio.options
43
+ @options = uio.options
44
44
  uio.session.logger.debug("#{self.class}: going to process '#{name}'")
45
45
  uio.output = @callback.call(*uio.params)
46
46
  @times_launched += 1
@@ -12,9 +12,12 @@ module Eco
12
12
 
13
13
  attr_reader :usecase
14
14
 
15
+ # @param usecase [Eco::API::UseCases::UseCase] the target `usecase`
16
+ # @param job [Eco::API::Session::Batch::Job] the default `job` of the usecase
15
17
  # @see Eco::API::UseCases::BaseIO#initialize
16
- def initialize(usecase:, **kargs)
18
+ def initialize(usecase:, job: nil, **kargs)
17
19
  self.usecase = usecase
20
+ @job = job
18
21
  super(**kargs)
19
22
  end
20
23
 
@@ -22,7 +25,11 @@ module Eco
22
25
  # @param usecase [Eco::API::UseCases::UseCase] target usecase
23
26
  # @return [Eco::API::UseCases::UseCaseIO]
24
27
  def new(usecase:, **kargs)
25
- super(**kargs.merge(usecase: usecase))
28
+ default = {
29
+ usecase: usecase,
30
+ job: @job
31
+ }
32
+ super(**default.merge(kargs))
26
33
  end
27
34
 
28
35
 
@@ -46,9 +53,12 @@ module Eco
46
53
  def params(keyed: false)
47
54
  super(keyed: keyed).tap do |res|
48
55
  if keyed
49
- res.merge!(usecase: usecase)
56
+ res.merge!({
57
+ usecase: usecase,
58
+ job: @job
59
+ })
50
60
  else
51
- res.push(usecase)
61
+ res.push(usecase).push(@job)
52
62
  end
53
63
  end
54
64
  end
@@ -64,7 +74,7 @@ module Eco
64
74
  kargs[:input] = output
65
75
  when :filter
66
76
  kargs[:people] = output
67
- when :transform, :sync, :export
77
+ when :transform, :sync, :export, :error_handler
68
78
  # no redirections => should it redirect the input?
69
79
  end
70
80
  self.class.new(kargs)
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.1"
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.2
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura