dirty_pipeline 0.6.4 → 0.7.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d44cfaa1fb0918cbce5275f04811600f667e9bcc539958cfd65e286f2dddb59
|
4
|
+
data.tar.gz: e0effe290c5f599d0f3cf692060768f0407a73e8c51f697be216fb2ada6d1df6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b44e2e14d5f1fd3b1b56ea9f6b567d585be488144d1beaf7aa38a47fa9fdb2ac986aef90c0a3f902ccfeacc069937ecec6b0f30b3866c9ef3aaa2760223dc6a
|
7
|
+
data.tar.gz: 3f7e985850e7cf8404c33d3855b314486ced5c64a28f7cb7cc3b97327fb616d85769cd854d3a2e98c4db615afb3c54b08492c338f8472a3148272b72794daf78
|
data/lib/dirty_pipeline/base.rb
CHANGED
@@ -22,8 +22,8 @@ module DirtyPipeline
|
|
22
22
|
using StringCamelcase
|
23
23
|
|
24
24
|
def transition(name, from:, to:, action: nil, attempts: 1)
|
25
|
-
action ||= const_get(name.to_s.camelcase(:upper)) rescue nil
|
26
25
|
action ||= method(name) if respond_to?(name)
|
26
|
+
action ||= const_get(name.to_s.camelcase(:upper))
|
27
27
|
@transitions_map[name.to_s] = {
|
28
28
|
action: action,
|
29
29
|
from: Array(from).map(&:to_s),
|
@@ -61,12 +61,13 @@ module DirtyPipeline
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# FIXME operation :call - argument
|
64
|
-
def chain(*args)
|
65
|
-
railway[
|
64
|
+
def chain(*args, operation: :call)
|
65
|
+
railway[operation] << Event.create(*args, tx_id: @uuid)
|
66
66
|
self
|
67
67
|
end
|
68
68
|
|
69
69
|
def call
|
70
|
+
# HANDLE ANOTHER ACTION IN PROGRESS EXPLICITLY
|
70
71
|
return self if (enqueued_event = railway.next).nil?
|
71
72
|
execute(load_event(enqueued_event))
|
72
73
|
end
|
@@ -106,6 +107,11 @@ module DirtyPipeline
|
|
106
107
|
def retry_delay; self.class.retry_delay || DEFAULT_RETRY_DELAY; end
|
107
108
|
def schedule_retry; schedule("retry", retry_delay); end
|
108
109
|
|
110
|
+
def when_skipped
|
111
|
+
yield(nil, self) if railway.other_transaction_in_progress?
|
112
|
+
self
|
113
|
+
end
|
114
|
+
|
109
115
|
def when_success
|
110
116
|
yield(status.data, self) if status.success?
|
111
117
|
self
|
@@ -118,10 +124,10 @@ module DirtyPipeline
|
|
118
124
|
|
119
125
|
private
|
120
126
|
|
121
|
-
|
122
127
|
def execute(event, attempt_retry: false)
|
123
128
|
attempt_retry ? event.attempt_retry! : event.start!
|
124
129
|
|
130
|
+
# dispatch event?
|
125
131
|
Transaction.new(self, event).call do |destination, action, *args|
|
126
132
|
state_changes = process_action(action, event, *args)
|
127
133
|
next if status.failure?
|
@@ -137,7 +143,7 @@ module DirtyPipeline
|
|
137
143
|
end
|
138
144
|
|
139
145
|
def process_action(action, event, *args)
|
140
|
-
|
146
|
+
catch(:success) do
|
141
147
|
return if interupt_on_error(event) do
|
142
148
|
throw :success, run_operation(action, event, *args)
|
143
149
|
end
|
@@ -149,6 +155,7 @@ module DirtyPipeline
|
|
149
155
|
end
|
150
156
|
|
151
157
|
def run_operation(action, event, *args)
|
158
|
+
raise ArgumentError unless action
|
152
159
|
return unless action.respond_to?(operation = railway.active)
|
153
160
|
action.public_send(operation, event, self, *args)
|
154
161
|
end
|
@@ -53,6 +53,11 @@ module DirtyPipeline
|
|
53
53
|
DirtyPipeline.with_redis { |r| r.get(active_transaction_key) }
|
54
54
|
end
|
55
55
|
|
56
|
+
def other_transaction_in_progress?
|
57
|
+
return false if running_transaction.nil?
|
58
|
+
running_transaction != @tx_id
|
59
|
+
end
|
60
|
+
|
56
61
|
private
|
57
62
|
|
58
63
|
def create_queue(operation_name)
|
@@ -75,10 +80,5 @@ module DirtyPipeline
|
|
75
80
|
def finish_transaction!
|
76
81
|
clear! if running_transaction == @tx_id
|
77
82
|
end
|
78
|
-
|
79
|
-
def other_transaction_in_progress?
|
80
|
-
return false if running_transaction.nil?
|
81
|
-
running_transaction != @tx_id
|
82
|
-
end
|
83
83
|
end
|
84
84
|
end
|
@@ -47,10 +47,10 @@ module DirtyPipeline
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def commit!(event)
|
50
|
-
store["status"] = event.destination
|
51
|
-
store["state"].merge!(event.changes)
|
50
|
+
store["status"] = event.destination if event.destination
|
51
|
+
store["state"].merge!(event.changes) unless event.changes.to_h.empty?
|
52
52
|
store["errors"][event.id] = event.error unless event.error.to_h.empty?
|
53
|
-
store["events"][event.id] = event.data
|
53
|
+
store["events"][event.id] = event.data unless event.data.to_h.empty?
|
54
54
|
save!
|
55
55
|
end
|
56
56
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dirty_pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Dolganov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|