dirty_pipeline 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dirty_pipeline.gemspec +0 -1
- data/lib/dirty_pipeline/base.rb +28 -41
- data/lib/dirty_pipeline/event.rb +2 -1
- data/lib/dirty_pipeline/storage.rb +1 -0
- data/lib/dirty_pipeline/transaction.rb +3 -12
- data/lib/dirty_pipeline/transition.rb +1 -5
- data/lib/dirty_pipeline/version.rb +1 -1
- data/lib/dirty_pipeline/worker.rb +2 -1
- data/lib/dirty_pipeline.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52d7e43f1786f53222062344f5ba1c21473d384981a7cf6ffddaa1980d707252
|
4
|
+
data.tar.gz: 7453aa7396775663b8f040fe507ec251dabefbc8e1d5ac2255eee919c65d2943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea9d73885acedf923e33f1ace3e3649142a2ca1615a402a78ff93b216a412b369668f14139fd688fa225eea26120d6fd1e668cf1cb18cd8c3fd76f79e974436f
|
7
|
+
data.tar.gz: ba2e70358c97d8e4fbd5af668f1db770b1d99cf292b7d8d42d661420bff553978d9961b676cdc1b1083a6ce70229c1c572cc1f3a10db9ec212287cc6f20a01b2
|
data/dirty_pipeline.gemspec
CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
# temporary dependency
|
25
25
|
spec.add_runtime_dependency "sidekiq", "~> 5.0"
|
26
26
|
spec.add_runtime_dependency "redis", "~> 4.0"
|
27
|
-
spec.add_runtime_dependency "nanoid", "~> 0.2.0"
|
28
27
|
|
29
28
|
spec.add_development_dependency "bundler", "~> 1.16"
|
30
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/dirty_pipeline/base.rb
CHANGED
@@ -35,7 +35,7 @@ module DirtyPipeline
|
|
35
35
|
|
36
36
|
attr_reader :subject, :storage, :status, :uuid, :queue, :railway
|
37
37
|
def initialize(subject, uuid: nil)
|
38
|
-
@uuid = uuid ||
|
38
|
+
@uuid = uuid || SecureRandom.uuid
|
39
39
|
@subject = subject
|
40
40
|
@storage = Storage.new(subject, self.class.pipeline_storage)
|
41
41
|
@railway = Railway.new(subject, @uuid)
|
@@ -60,34 +60,29 @@ module DirtyPipeline
|
|
60
60
|
reset!
|
61
61
|
end
|
62
62
|
|
63
|
+
# FIXME operation :call - argument
|
63
64
|
def chain(*args)
|
64
65
|
railway[:call] << Event.create(*args, tx_id: @uuid)
|
65
66
|
self
|
66
67
|
end
|
67
68
|
|
68
69
|
def call
|
69
|
-
return self if (
|
70
|
-
execute(load_event(
|
70
|
+
return self if (enqueued_event = railway.next).nil?
|
71
|
+
execute(load_event(enqueued_event))
|
71
72
|
end
|
72
73
|
alias :call_next :call
|
73
74
|
|
74
75
|
def clean
|
76
|
+
finished = railway.queue.to_a.empty?
|
77
|
+
finished &&= railway.queue.processing_event.nil?
|
78
|
+
return self if finished
|
75
79
|
railway.switch_to(:undo)
|
76
|
-
|
77
|
-
self
|
80
|
+
call
|
78
81
|
end
|
79
82
|
|
80
83
|
def retry
|
81
|
-
return
|
82
|
-
execute(
|
83
|
-
end
|
84
|
-
|
85
|
-
def schedule_cleanup
|
86
|
-
schedule("cleanup", cleanup_delay)
|
87
|
-
end
|
88
|
-
|
89
|
-
def schedule_retry
|
90
|
-
schedule("retry", retry_delay)
|
84
|
+
return self if (enqueued_event = railway.queue.processing_event).nil?
|
85
|
+
execute(load_event(enqueued_event), attempt_retry: true)
|
91
86
|
end
|
92
87
|
|
93
88
|
def schedule(operation, delay = nil)
|
@@ -105,6 +100,12 @@ module DirtyPipeline
|
|
105
100
|
end
|
106
101
|
end
|
107
102
|
|
103
|
+
def cleanup_delay; self.class.cleanup_delay || DEFAULT_CLEANUP_DELAY; end
|
104
|
+
def schedule_cleanup; schedule("cleanup", cleanup_delay); end
|
105
|
+
|
106
|
+
def retry_delay; self.class.retry_delay || DEFAULT_RETRY_DELAY; end
|
107
|
+
def schedule_retry; schedule("retry", retry_delay); end
|
108
|
+
|
108
109
|
def when_success
|
109
110
|
yield(status.data, self) if status.success?
|
110
111
|
self
|
@@ -117,8 +118,11 @@ module DirtyPipeline
|
|
117
118
|
|
118
119
|
private
|
119
120
|
|
120
|
-
|
121
|
-
|
121
|
+
|
122
|
+
def execute(event, attempt_retry: false)
|
123
|
+
attempt_retry ? event.attempt_retry! : event.start!
|
124
|
+
|
125
|
+
Transaction.new(self, event).call do |destination, action, *args|
|
122
126
|
state_changes = process_action(action, event, *args)
|
123
127
|
next if status.failure?
|
124
128
|
Success(event, state_changes, destination)
|
@@ -140,45 +144,28 @@ module DirtyPipeline
|
|
140
144
|
nil
|
141
145
|
end
|
142
146
|
rescue => exception
|
143
|
-
|
147
|
+
Failure(event, exception, type: :exception)
|
144
148
|
raise
|
145
149
|
end
|
146
150
|
|
147
151
|
def run_operation(action, event, *args)
|
148
|
-
return unless action.respond_to?(operation = railway.
|
152
|
+
return unless action.respond_to?(operation = railway.active)
|
149
153
|
action.public_send(operation, event, self, *args)
|
150
154
|
end
|
151
155
|
|
152
156
|
def interupt_on_error(event)
|
153
|
-
return unless (fail_cause = catch(:
|
154
|
-
Failure(event, fail_cause)
|
157
|
+
return unless (fail_cause = catch(:fail_transition) { yield; nil })
|
158
|
+
Failure(event, fail_cause, type: :error)
|
155
159
|
end
|
156
160
|
|
157
161
|
def find_subject_args
|
158
162
|
subject.id
|
159
163
|
end
|
160
164
|
|
161
|
-
def
|
162
|
-
self.class.retry_delay || DEFAULT_RETRY_DELAY
|
163
|
-
end
|
164
|
-
|
165
|
-
def cleanup_delay
|
166
|
-
self.class.cleanup_delay || DEFAULT_CLEANUP_DELAY
|
167
|
-
end
|
168
|
-
|
169
|
-
def transaction(event)
|
170
|
-
Transaction.new(self, event)
|
171
|
-
end
|
172
|
-
|
173
|
-
def Failure(event, cause)
|
165
|
+
def Failure(event, cause, type:)
|
174
166
|
railway.switch_to(:undo)
|
175
|
-
|
176
|
-
|
177
|
-
@status = Status.failure(subject, tag: :aborted)
|
178
|
-
else
|
179
|
-
event.failure!
|
180
|
-
@status = Status.failure(cause, tag: :error)
|
181
|
-
end
|
167
|
+
event.failure!
|
168
|
+
@status = Status.failure(cause, tag: type)
|
182
169
|
throw :abort_transaction, true
|
183
170
|
end
|
184
171
|
|
data/lib/dirty_pipeline/event.rb
CHANGED
@@ -9,18 +9,6 @@ module DirtyPipeline
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call
|
12
|
-
event.start!
|
13
|
-
with_transaction { |*targs| yield(*targs) }
|
14
|
-
end
|
15
|
-
|
16
|
-
def retry
|
17
|
-
event.attempt_retry!
|
18
|
-
with_transaction { |*targs| yield(*targs) }
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def with_transaction
|
24
12
|
pipeline.schedule_cleanup
|
25
13
|
|
26
14
|
destination, action, max_attempts_count =
|
@@ -29,6 +17,7 @@ module DirtyPipeline
|
|
29
17
|
|
30
18
|
storage.commit!(event)
|
31
19
|
|
20
|
+
# FIXME: make configurable, now - hardcoded to AR API
|
32
21
|
subject.transaction(requires_new: true) do
|
33
22
|
with_abort_handling { yield(destination, action, *event.args) }
|
34
23
|
end
|
@@ -43,6 +32,8 @@ module DirtyPipeline
|
|
43
32
|
storage.commit!(event)
|
44
33
|
end
|
45
34
|
|
35
|
+
private
|
36
|
+
|
46
37
|
def with_abort_handling
|
47
38
|
return unless catch(:abort_transaction) { yield; nil }
|
48
39
|
event.abort! unless event.abort?
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# FIXME: Abstract worker (see ActiveJob)
|
1
2
|
require 'sidekiq'
|
2
3
|
module DirtyPipeline
|
3
4
|
class Worker
|
@@ -17,7 +18,7 @@ module DirtyPipeline
|
|
17
18
|
|
18
19
|
case operation
|
19
20
|
when "cleanup"
|
20
|
-
pipeline.clean
|
21
|
+
return pipeline.clean
|
21
22
|
when "retry"
|
22
23
|
return pipeline.retry
|
23
24
|
end
|
data/lib/dirty_pipeline.rb
CHANGED
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
|
+
version: 0.6.1
|
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-
|
11
|
+
date: 2018-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: nanoid
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|