business_flow 0.21.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/business_flow/cluster_lock.rb +30 -29
- data/lib/business_flow/dsl.rb +11 -4
- data/lib/business_flow/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: 58b3100df6d7fe1c1a09846cec4cd3df8692e7c8ab6a1a5f59387bddd116adf9
|
|
4
|
+
data.tar.gz: cc3a48bc0b5cb9932b921ebabfab8ceaf5ce64b292f7eed5e2c48e58f37912c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a50eaa3074e7369e57ff20f715f77c332fbea9dc2f2904fb8cbe84e8aafcc20f0b7dc1f7c3d9681642b7b3b6db8106d8ab6bad6367368e93a81145db6a7f6381
|
|
7
|
+
data.tar.gz: 4ce3770b14b51f01b77e0bbe57d990fe0ea6156539a5154afe99a99436cd07b0ff9787b7da1a4d5757adff719d0bcbe7842f72f996c9b9578ee5eb0453c7143c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## 0.21.1
|
|
2
|
+
|
|
3
|
+
ENHANCEMENTS:
|
|
4
|
+
|
|
5
|
+
* Added #failure_exception= to flow classes for setting an exception causing a failure. Setting an exception also fails the flow execution.
|
|
6
|
+
* Added #exception to flow result classes for reading the exception causing a failure.
|
|
7
|
+
* Set #exception as the cause: on FlowFailedException.
|
|
8
|
+
* ClusterLock now propogates Zookeeper errors through failure_exception and the case on its LockFailure exception.
|
|
9
|
+
|
|
1
10
|
## 0.21.0
|
|
2
11
|
|
|
3
12
|
BUG FIXES:
|
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
module BusinessFlow
|
|
4
4
|
# Mixin for business flow to acquire and retain a cluster lock.
|
|
5
5
|
module ClusterLock
|
|
6
|
+
# Error raised when there is an internal issue with acquiring a lock.
|
|
7
|
+
class LockFailure < StandardError
|
|
8
|
+
attr_reader :error_type
|
|
9
|
+
|
|
10
|
+
def initialize(error_type, message)
|
|
11
|
+
@error_type = error_type
|
|
12
|
+
super(message)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add_to(flow)
|
|
16
|
+
errors = flow.errors
|
|
17
|
+
unless errors.key?(:cluster_lock)
|
|
18
|
+
BusinessFlow.add_error(errors, :cluster_lock, error_type, message)
|
|
19
|
+
end
|
|
20
|
+
flow.failure_exception = self
|
|
21
|
+
flow
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Holder for information about the lock
|
|
26
|
+
class LockInfo
|
|
27
|
+
attr_reader :lock_name, :zookeeper_servers
|
|
28
|
+
|
|
29
|
+
def initialize(lock_name, zookeeper_servers)
|
|
30
|
+
@lock_name = lock_name
|
|
31
|
+
@zookeeper_servers = zookeeper_servers
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
6
35
|
def self.included(klass)
|
|
7
36
|
klass.extend(ClassMethods)
|
|
8
37
|
end
|
|
@@ -51,34 +80,6 @@ module BusinessFlow
|
|
|
51
80
|
|
|
52
81
|
# DSL Methods
|
|
53
82
|
module ClassMethods # rubocop:disable Metrics/ModuleLength
|
|
54
|
-
# Error raised when there is an internal issue with acquiring a lock.
|
|
55
|
-
class LockFailure < StandardError
|
|
56
|
-
attr_reader :error_type
|
|
57
|
-
|
|
58
|
-
def initialize(error_type, message)
|
|
59
|
-
@error_type = error_type
|
|
60
|
-
super(message)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def add_to(flow)
|
|
64
|
-
errors = flow.errors
|
|
65
|
-
unless errors.key?(:cluster_lock)
|
|
66
|
-
BusinessFlow.add_error(errors, :cluster_lock, error_type, message)
|
|
67
|
-
end
|
|
68
|
-
flow
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Holder for information about the lock
|
|
73
|
-
class LockInfo
|
|
74
|
-
attr_reader :lock_name, :zookeeper_servers
|
|
75
|
-
|
|
76
|
-
def initialize(lock_name, zookeeper_servers)
|
|
77
|
-
@lock_name = lock_name
|
|
78
|
-
@zookeeper_servers = zookeeper_servers
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
83
|
def with_cluster_lock(lock_name = nil, opts = {}, &blk)
|
|
83
84
|
if lock_name.is_a?(String)
|
|
84
85
|
@lock_name = Step.new(Callable.new(proc { lock_name }), {})
|
|
@@ -216,7 +217,7 @@ module BusinessFlow
|
|
|
216
217
|
rescue ZK::Exceptions::LockAssertionFailedError, ZK::Exceptions::OperationTimeOut => e
|
|
217
218
|
# This would occur if we asserted a cluster lock while executing the flow.
|
|
218
219
|
# This will have set an error on the flow, so we can carry on.
|
|
219
|
-
raise LockFailure.new(exception_to_error_type(e), e.message)
|
|
220
|
+
raise LockFailure.new(exception_to_error_type(e), e.message), cause: e
|
|
220
221
|
ensure
|
|
221
222
|
cleanup(lock, zk_connection)
|
|
222
223
|
end
|
data/lib/business_flow/dsl.rb
CHANGED
|
@@ -128,7 +128,7 @@ module BusinessFlow
|
|
|
128
128
|
|
|
129
129
|
def call!(*args)
|
|
130
130
|
flow = call(*args)
|
|
131
|
-
raise FlowFailedException, flow if flow.errors?
|
|
131
|
+
raise FlowFailedException, flow, cause: flow.exception if flow.errors?
|
|
132
132
|
|
|
133
133
|
flow
|
|
134
134
|
end
|
|
@@ -154,7 +154,8 @@ module BusinessFlow
|
|
|
154
154
|
# We use instance_variable_get here instead of making it part of
|
|
155
155
|
# from_flow to ensure that we do not create the errors object unless
|
|
156
156
|
# we need it.
|
|
157
|
-
result = const_get(:Result).new(flow.instance_variable_get(:@errors)
|
|
157
|
+
result = const_get(:Result).new(flow.instance_variable_get(:@errors),
|
|
158
|
+
flow.send(:failure_exception))
|
|
158
159
|
result.from_flow(flow) if @result_copy
|
|
159
160
|
result
|
|
160
161
|
end
|
|
@@ -205,8 +206,11 @@ module BusinessFlow
|
|
|
205
206
|
|
|
206
207
|
RESULT_DEF = %(
|
|
207
208
|
class Result
|
|
208
|
-
|
|
209
|
+
attr_reader :exception
|
|
210
|
+
|
|
211
|
+
def initialize(errors, exception)
|
|
209
212
|
@errors = errors
|
|
213
|
+
@exception = exception
|
|
210
214
|
end
|
|
211
215
|
|
|
212
216
|
def errors
|
|
@@ -216,7 +220,7 @@ module BusinessFlow
|
|
|
216
220
|
def errors?
|
|
217
221
|
# We're explicitly using the instance variable here so that if no
|
|
218
222
|
# errors have been created, we don't initialize the error object.
|
|
219
|
-
!!@errors && @errors.present?
|
|
223
|
+
(!!@errors && @errors.present?) || !exception.nil?
|
|
220
224
|
end
|
|
221
225
|
|
|
222
226
|
def valid?(_context = nil)
|
|
@@ -263,6 +267,9 @@ module BusinessFlow
|
|
|
263
267
|
attr_reader :parameter_object
|
|
264
268
|
private :parameter_object
|
|
265
269
|
|
|
270
|
+
attr_accessor :failure_exception
|
|
271
|
+
private :failure_exception
|
|
272
|
+
|
|
266
273
|
def call
|
|
267
274
|
return if invalid?
|
|
268
275
|
|