sagas 0.0.0 → 0.0.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/lib/sagas.rb +26 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6130b14df41d9e8ef58acd7f83ae1855dd7df66
|
4
|
+
data.tar.gz: 18103acc218313e7eb9db7bde80c7b4b518c06b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2053abdc45d08fe8f7c984bf814aca113fa9fdd26c17a44f4a50b3e76572e9d4f6b00345c4b930cc303e4da83a4eb8b0179f18375c7974edb92bb521344e7c32
|
7
|
+
data.tar.gz: a56f9850ae727212842efb8bb9e42a8b7eab1474812f0bc10ef45b75fdb3e18926b7877873aa99e5fd7796112b7c80f67d7d0ccdc42752d8ded57d42868b9759
|
data/lib/sagas.rb
CHANGED
@@ -1,34 +1,40 @@
|
|
1
1
|
class Effect
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
(class << self; self; end).class_eval do
|
6
|
-
define_method :transaction do
|
7
|
-
transaction.call
|
8
|
-
end
|
2
|
+
attr_reader :name, :perform, :undo
|
3
|
+
attr_accessor :side_effect
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
def initialize(name:, perform:, undo:)
|
6
|
+
@name = name
|
7
|
+
@perform = perform
|
8
|
+
@undo = undo
|
14
9
|
end
|
15
10
|
end
|
16
11
|
|
17
12
|
class Saga
|
18
|
-
|
13
|
+
def initialize
|
14
|
+
@effects = []
|
15
|
+
# Can be :abort, :error, or :ok
|
16
|
+
@transaction_state = :ok
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.transaction(&block)
|
20
|
+
block.call(Saga.new)
|
21
|
+
end
|
19
22
|
|
20
|
-
def
|
21
|
-
|
23
|
+
def run(name:, perform:, undo:)
|
24
|
+
add_stage(name: name, perform: perform, undo: undo)
|
25
|
+
execute_stage if @transaction_state == :ok
|
22
26
|
end
|
23
27
|
|
24
|
-
def
|
25
|
-
|
26
|
-
@actions.push(action)
|
28
|
+
def add_stage(name:, perform:, undo:)
|
29
|
+
@effects.push(Effect.new(name: name, perform: perform, undo: undo))
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
+
def execute_stage
|
33
|
+
@effects.last.side_effect = @effects.last.perform.call()
|
34
|
+
rescue => e
|
35
|
+
@transaction_state = :abort
|
36
|
+
@effects.reverse_each do |effect|
|
37
|
+
effect.undo.call(effect.side_effect)
|
32
38
|
end
|
33
39
|
end
|
34
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sagas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Yu
|
@@ -11,7 +11,7 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2018-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: A dependency-free library to manage distributed transactions in Ruby
|
15
15
|
email: victor.yu.canada@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
@@ -41,5 +41,5 @@ rubyforge_project:
|
|
41
41
|
rubygems_version: 2.5.2
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
|
-
summary: A Ruby implementation of
|
44
|
+
summary: A Ruby implementation of the Saga design pattern
|
45
45
|
test_files: []
|