saga_orchestrator 0.15 → 0.17
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/Readme.md +4 -4
- data/examples/main.rb +2 -2
- data/examples/workflow_models/definitions/test.rb +17 -4
- data/examples/workflow_models/functions/test.rb +7 -0
- data/lib/state_management/sequences.rb +17 -3
- data/lib/state_management/state_engine.rb +2 -1
- data/lib/state_management/states.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cd99f62af35797ca43befbb1b88703e54d6e0d115c11f8bab5df7f8ed6a7fdd
|
4
|
+
data.tar.gz: 243c00eede8dc09ccbe45b72301db3237a9ed09c1d03a135291ebe4e01ff7439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83b097c7b8ffdfed0e33d32749273756fde8c8cc0340eb58b3b15e63ef0595ce60c5d1f59ecbebcefd2c9209ccb8cd7999b90fe260978f797bf6bcbd5f9af66c
|
7
|
+
data.tar.gz: f228f9ccc927995f41b61ad483621703a3ba4e4d87d32578b0d8df97728d231b0f0e393d431c78ff7cfd5f62fa97620e832a07fce5cdb1b33b4b882ee69aed48
|
data/Readme.md
CHANGED
@@ -4,6 +4,8 @@ Saga Orchestration gem is inspired by Microservice Patterns by Chris Richardson.
|
|
4
4
|
|
5
5
|
It provides a framework to employ the Saga Orchestration patterns described in detail in his books and articles. Secondly, it makes it easier for firms to visualize the entire flow as a set of steps.
|
6
6
|
|
7
|
+
This is available on github at: [Saga Orchestration Gem](https://github.com/jravz/saga_orchestrator)
|
8
|
+
|
7
9
|
## Description
|
8
10
|
|
9
11
|
The key goals this gem seeks to address are -
|
@@ -44,10 +46,9 @@ To build workflows, the first step is to design the workflow. Let us take an exa
|
|
44
46
|

|
45
47
|
|
46
48
|
1. Create a child class inheriting from Saga::StateEngine
|
47
|
-
2. Add a function
|
49
|
+
2. Add a function state_registration within the child class as below to setup all the states as below. Use register_states features to register various states.
|
48
50
|
|
49
|
-
|
50
|
-
def state_registration
|
51
|
+
def state_registration
|
51
52
|
|
52
53
|
register_states do |add_state|
|
53
54
|
|
@@ -102,7 +103,6 @@ def state_registration
|
|
102
103
|
end
|
103
104
|
|
104
105
|
end
|
105
|
-
'''
|
106
106
|
|
107
107
|
### How to define a state
|
108
108
|
|
data/examples/main.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'saga_orchestrator'
|
1
|
+
require '../lib/saga_orchestrator'
|
2
2
|
require_relative 'workflow_models/definitions/test'
|
3
3
|
|
4
|
-
obj = Saga::Orchestrator::new(Workflows::Test,
|
4
|
+
obj = Saga::Orchestrator::new(Workflows::Test, 3000)
|
5
5
|
puts obj.run()
|
6
6
|
puts obj.execution_sequence
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../../../lib/saga_orchestrator'
|
2
2
|
require_relative '../processors/test'
|
3
3
|
require_relative '../functions/test'
|
4
4
|
require_relative '../rollback/test'
|
@@ -42,6 +42,14 @@ module Workflows
|
|
42
42
|
state.process_output Processors::Test.method(:processor)
|
43
43
|
end
|
44
44
|
|
45
|
+
add_state.standard :sample4 do |state|
|
46
|
+
state.call Functions::Test.method(:test_func4)
|
47
|
+
state.params do |p|
|
48
|
+
p.set_type :input_params
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
45
53
|
add_state.standard :cond01 do |state|
|
46
54
|
state.call Functions::Test.method(:conditional_test)
|
47
55
|
state.params do |p|
|
@@ -55,14 +63,19 @@ module Workflows
|
|
55
63
|
|
56
64
|
def sequence_states
|
57
65
|
describe_flows do |seqs|
|
66
|
+
|
67
|
+
seqs.sub :seq_b do |seq|
|
68
|
+
seq.init state_name :sample4
|
69
|
+
seq.end
|
70
|
+
end
|
71
|
+
|
58
72
|
seqs.start :seq_a do |seq|
|
59
73
|
seq.init state_name :sample
|
60
74
|
seq.then state_name :sample2
|
61
75
|
seq.then_conditional state_name :cond01 do |t|
|
62
|
-
t.on_true
|
63
|
-
t.on_false state_name :
|
76
|
+
t.on_true sequence_name :seq_b
|
77
|
+
t.on_false state_name :sample3
|
64
78
|
end
|
65
|
-
seq.then state_name :sample3
|
66
79
|
seq.end
|
67
80
|
end
|
68
81
|
end
|
@@ -18,6 +18,13 @@ module Functions
|
|
18
18
|
raise StandardError, "An error occurred"
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.test_func4 input
|
22
|
+
puts "in test_func: input - #{input}"
|
23
|
+
res = input * 10000
|
24
|
+
puts "result = #{res}"
|
25
|
+
res
|
26
|
+
end
|
27
|
+
|
21
28
|
def self.conditional_test input
|
22
29
|
res = input > 0
|
23
30
|
puts "result = #{res}"
|
@@ -21,6 +21,12 @@ module Saga
|
|
21
21
|
@run_state = nil
|
22
22
|
end
|
23
23
|
|
24
|
+
def set_run_status bool
|
25
|
+
if bool.is_a?(TrueClass) || bool.is_a?(FalseClass)
|
26
|
+
@run_state = bool
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
24
30
|
def run params = nil, last_state_result=nil
|
25
31
|
|
26
32
|
if self.type == :stop
|
@@ -44,7 +50,7 @@ module Saga
|
|
44
50
|
def next
|
45
51
|
|
46
52
|
if @run_state.nil?
|
47
|
-
raise NodeNotRunError.new("Node has not been run yet.", { reason: "Next can only be decided after node has been run.", code: 1001 })
|
53
|
+
raise NodeNotRunError.new("Node has not been run yet.: #{self.name}", { reason: "Next can only be decided after node has been run.", code: 1001 })
|
48
54
|
end
|
49
55
|
|
50
56
|
if @run_state == true
|
@@ -61,14 +67,18 @@ module Saga
|
|
61
67
|
def set_do task
|
62
68
|
|
63
69
|
if task.nil?
|
64
|
-
raise NullStateError.new("
|
70
|
+
raise NullStateError.new("Attempt to run an undefined state.", { reason: "State has not been defined or registered.", code: 1001 })
|
65
71
|
end
|
66
72
|
|
67
73
|
if task.is_a?(Sequence)
|
68
74
|
@action_type = :sequence
|
75
|
+
@name = task.name
|
76
|
+
puts "within sequence - #{@name}"
|
77
|
+
else
|
78
|
+
@name = task.state_name
|
79
|
+
puts "within task - #{@name}"
|
69
80
|
end
|
70
81
|
@do = task
|
71
|
-
@name = task.state_name
|
72
82
|
end
|
73
83
|
|
74
84
|
def name
|
@@ -152,6 +162,10 @@ module Saga
|
|
152
162
|
@initial_node = nil
|
153
163
|
end
|
154
164
|
|
165
|
+
def name
|
166
|
+
@name
|
167
|
+
end
|
168
|
+
|
155
169
|
def first
|
156
170
|
@initial_node
|
157
171
|
end
|
@@ -86,8 +86,9 @@ module Saga
|
|
86
86
|
current_node = active_node
|
87
87
|
|
88
88
|
begin
|
89
|
-
if current_node.
|
89
|
+
if current_node.sequence?
|
90
90
|
conduct_sequence current_node.activity.first
|
91
|
+
current_node.set_run_status true
|
91
92
|
else
|
92
93
|
@executing_node = current_node
|
93
94
|
res = current_node.run @params, @last_result
|
@@ -30,7 +30,9 @@ module Saga
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def get_state_by_name name
|
33
|
-
@states[name]
|
33
|
+
res = @states[name]
|
34
|
+
raise NullStateError.new("Attempt to run an undefined state = #{name}.", { reason: "State has not been defined or registered.", code: 1001 }) if res.nil?
|
35
|
+
res
|
34
36
|
end
|
35
37
|
|
36
38
|
def keys
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saga_orchestrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.17'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayanth Ravindran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Framework to help employ the Saga Orchestration patterns in ruby or rails
|
14
14
|
applications. Secondly, it makes it easier for firms to visualize the entire flow
|