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 +4 -4
- data/lib/eco/api/error.rb +4 -0
- data/lib/eco/api/error/handler.rb +2 -2
- data/lib/eco/api/error/handlers.rb +1 -1
- data/lib/eco/api/session/batch/feedback.rb +9 -1
- data/lib/eco/api/session/batch/job.rb +19 -3
- data/lib/eco/api/usecases/base_case.rb +1 -1
- data/lib/eco/api/usecases/base_io.rb +11 -3
- data/lib/eco/api/usecases/use_case.rb +1 -1
- data/lib/eco/api/usecases/use_case_io.rb +15 -5
- data/lib/eco/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adb97e964a09a628b29aa507f3f6d764df82b7c8dbdd568f86245ab05fdfb4bb
|
4
|
+
data.tar.gz: 1f09ede76add050f3800d6683717a1ccd8f45e6af46f030e53d24edee74f7273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0d9585e4c20c5e9f0f8ca0101789dc9e50e6e08a71297c0376f1c2334abe602fbe24ca5fee178c840c2c52e0ee6a1446c26eee0103a377f29e99fbe9afece46
|
7
|
+
data.tar.gz: e3894a74b853858da71ee783f460eed18cbd68dae92a941ea755a687b84c7b27f4899a675c7cb16ecbb83d0eb4105aa8380d8dea3ac64493a7e82f6802a14e37
|
data/lib/eco/api/error.rb
CHANGED
@@ -2,9 +2,9 @@ module Eco
|
|
2
2
|
module API
|
3
3
|
class Error
|
4
4
|
class Handler < Eco::API::UseCases::UseCase
|
5
|
-
@types = [:
|
5
|
+
@types = [:error_handler]
|
6
6
|
|
7
|
-
def initialize(name, type: :
|
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: :
|
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
|
-
#
|
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
|
-
|
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
|
@@ -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(
|
58
|
-
|
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
|
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
|
-
|
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!(
|
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