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: 39b6905344a3e533c084d66709bc992996351b5ca52b1a49bd995ab5159ea7eb
4
- data.tar.gz: 19176034e183e583454c99ddb72309ef1ee7b7e2db05de9d9affadae5d652dfe
3
+ metadata.gz: 1d44cfaa1fb0918cbce5275f04811600f667e9bcc539958cfd65e286f2dddb59
4
+ data.tar.gz: e0effe290c5f599d0f3cf692060768f0407a73e8c51f697be216fb2ada6d1df6
5
5
  SHA512:
6
- metadata.gz: 7e4ed6d5dbfc6f015ad05065a2e571481f979d7d70265da262a8a7d8a650a09a6e6c8d99671fdd3f07ab320442022075d90db51c148f1b5d1e9fd172047a8fba
7
- data.tar.gz: d1e2a3f6a925add414c6935448986c272d618a2d5f9783016406385d30d3e566b455ea5c66d054df16900b23bfe9f0c567a2fe758884c64aadb2d3eb42bf4ed2
6
+ metadata.gz: 9b44e2e14d5f1fd3b1b56ea9f6b567d585be488144d1beaf7aa38a47fa9fdb2ac986aef90c0a3f902ccfeacc069937ecec6b0f30b3866c9ef3aaa2760223dc6a
7
+ data.tar.gz: 3f7e985850e7cf8404c33d3855b314486ced5c64a28f7cb7cc3b97327fb616d85769cd854d3a2e98c4db615afb3c54b08492c338f8472a3148272b72794daf78
@@ -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[:call] << Event.create(*args, tx_id: @uuid)
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
- return catch(:success) do
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 if event.destination
51
- store["state"].merge!(event.changes) unless event.changes.to_h.empty?
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 unless event.data.to_h.empty?
53
+ store["events"][event.id] = event.data unless event.data.to_h.empty?
54
54
  save!
55
55
  end
56
56
 
@@ -11,6 +11,7 @@ module DirtyPipeline
11
11
  def call
12
12
  pipeline.schedule_cleanup
13
13
 
14
+ # Split attempts config and event dispatching
14
15
  destination, action, max_attempts_count =
15
16
  pipeline.find_transition(event.transition)
16
17
  .values_at(:to, :action, :attempts)
@@ -14,6 +14,7 @@ module DirtyPipeline
14
14
  end
15
15
  throw :success, changes.to_h
16
16
  end
17
+
17
18
  def self.finalize(*args, **kwargs)
18
19
  event, pipeline, *args = args
19
20
  instance = new(event, pipeline.railway, *args, **kwargs)
@@ -1,3 +1,3 @@
1
1
  module DirtyPipeline
2
- VERSION = "0.6.4"
2
+ VERSION = "0.7.0"
3
3
  end
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.6.4
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-09-17 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq