dynflow 0.0.1 → 0.1.0
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.
- data/Gemfile +12 -4
- data/README.md +4 -4
- data/Rakefile +9 -1
- data/dynflow.gemspec +1 -1
- data/examples/events.rb +5 -5
- data/examples/workflow.rb +4 -4
- data/lib/dynflow.rb +3 -3
- data/lib/dynflow/action.rb +27 -18
- data/lib/dynflow/bus.rb +136 -24
- data/lib/dynflow/dispatcher.rb +1 -1
- data/lib/dynflow/execution_plan.rb +56 -0
- data/lib/dynflow/step.rb +234 -0
- data/lib/dynflow/version.rb +1 -1
- data/test/action_test.rb +6 -5
- data/test/bus_test.rb +127 -32
- data/test/execution_plan_test.rb +121 -0
- data/test/test_helper.rb +1 -80
- metadata +7 -8
- data/lib/dynflow/message.rb +0 -38
- data/lib/dynflow/orch_request.rb +0 -14
- data/lib/dynflow/orch_response.rb +0 -5
- data/test/dispatcher_test.rb +0 -108
data/test/test_helper.rb
CHANGED
@@ -1,83 +1,4 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'minitest/spec'
|
3
3
|
require 'dynflow'
|
4
|
-
|
5
|
-
BUS_IMPL = Dynflow::Bus::MemoryBus
|
6
|
-
|
7
|
-
class TestBus < BUS_IMPL
|
8
|
-
|
9
|
-
def initialize(expected_scenario)
|
10
|
-
super()
|
11
|
-
@expected_scenario = expected_scenario
|
12
|
-
end
|
13
|
-
|
14
|
-
def process(action_class, input, output = nil, stub = true)
|
15
|
-
expected = @expected_scenario.shift
|
16
|
-
if action_class == TestScenarioFinalizer || !stub || output
|
17
|
-
return super(action_class, input, output)
|
18
|
-
elsif action_class.name == expected[:action_class].name && input == expected[:input]
|
19
|
-
return action_class.new(expected[:input], expected[:output])
|
20
|
-
else
|
21
|
-
raise "Unexpected input. Expected #{expected[:action_class]} #{expected[:input].inspect}, got #{action_class} #{input.inspect}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
class TestScenarioFinalizer < Dynflow::Action
|
28
|
-
|
29
|
-
class << self
|
30
|
-
|
31
|
-
def recorded_outputs
|
32
|
-
@recorded_outputs
|
33
|
-
end
|
34
|
-
|
35
|
-
def init_recorded_outputs
|
36
|
-
@recorded_outputs = []
|
37
|
-
end
|
38
|
-
|
39
|
-
def save_recorded_outputs(recorded_outputs)
|
40
|
-
@recorded_outputs = recorded_outputs
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def finalize(outputs)
|
46
|
-
self.class.save_recorded_outputs(outputs)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
class BusTestCase < Test::Unit::TestCase
|
52
|
-
|
53
|
-
def setup
|
54
|
-
@expected_scenario = []
|
55
|
-
end
|
56
|
-
|
57
|
-
def expect_input(action_class, input, output)
|
58
|
-
@expected_scenario << {
|
59
|
-
:action_class => action_class,
|
60
|
-
:input => input,
|
61
|
-
:output => output
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
def assert_scenario
|
66
|
-
Dynflow::Bus.impl = TestBus.new(@expected_scenario)
|
67
|
-
event_outputs = nil
|
68
|
-
TestScenarioFinalizer.init_recorded_outputs
|
69
|
-
execution_plan = self.execution_plan
|
70
|
-
execution_plan << [TestScenarioFinalizer, {}]
|
71
|
-
Dynflow::Bus.trigger(execution_plan)
|
72
|
-
return TestScenarioFinalizer.recorded_outputs
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class ParticipantTestCase < Test::Unit::TestCase
|
77
|
-
|
78
|
-
def run_action(action_class, input)
|
79
|
-
Dynflow::Bus.impl = Dynflow::Bus.new
|
80
|
-
output = Dynflow::Bus.process(action_class, input)
|
81
|
-
return output
|
82
|
-
end
|
83
|
-
end
|
4
|
+
require 'pry'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -95,16 +95,15 @@ files:
|
|
95
95
|
- lib/dynflow/action.rb
|
96
96
|
- lib/dynflow/bus.rb
|
97
97
|
- lib/dynflow/dispatcher.rb
|
98
|
+
- lib/dynflow/execution_plan.rb
|
98
99
|
- lib/dynflow/logger.rb
|
99
|
-
- lib/dynflow/
|
100
|
-
- lib/dynflow/orch_request.rb
|
101
|
-
- lib/dynflow/orch_response.rb
|
100
|
+
- lib/dynflow/step.rb
|
102
101
|
- lib/dynflow/version.rb
|
103
102
|
- test/action_test.rb
|
104
103
|
- test/bus_test.rb
|
105
|
-
- test/
|
104
|
+
- test/execution_plan_test.rb
|
106
105
|
- test/test_helper.rb
|
107
|
-
homepage: http://github.com/iNecas/
|
106
|
+
homepage: http://github.com/iNecas/dynflow
|
108
107
|
licenses: []
|
109
108
|
post_install_message:
|
110
109
|
rdoc_options: []
|
@@ -131,5 +130,5 @@ summary: DYNamic workFLOW engine
|
|
131
130
|
test_files:
|
132
131
|
- test/action_test.rb
|
133
132
|
- test/bus_test.rb
|
134
|
-
- test/
|
133
|
+
- test/execution_plan_test.rb
|
135
134
|
- test/test_helper.rb
|
data/lib/dynflow/message.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
-
require 'active_support/core_ext/string/inflections'
|
4
|
-
require 'apipie-params'
|
5
|
-
|
6
|
-
module Dynflow
|
7
|
-
class Message
|
8
|
-
|
9
|
-
def ==(other)
|
10
|
-
self.encode == other.encode
|
11
|
-
end
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
|
15
|
-
def_delegators :@data, '[]', '[]='
|
16
|
-
|
17
|
-
attr_reader :data
|
18
|
-
|
19
|
-
def initialize(data = {})
|
20
|
-
@data = data.with_indifferent_access
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def self.decode(data)
|
25
|
-
ret = data['message_type'].constantize.allocate
|
26
|
-
ret.instance_variable_set("@data", data['data'])
|
27
|
-
return ret
|
28
|
-
end
|
29
|
-
|
30
|
-
def encode
|
31
|
-
{
|
32
|
-
'message_type' => self.class.name,
|
33
|
-
'data' => @data
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
data/lib/dynflow/orch_request.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Dynflow
|
2
|
-
class OrchRequest < Message
|
3
|
-
def self.response_class
|
4
|
-
unless self.name =~ /::Request\Z/
|
5
|
-
raise "Unexpected class name, #{self.name} expected to end with ::Request"
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
self.name.sub(/::Request\Z/, '::Response').constantize
|
9
|
-
rescue NameError => e
|
10
|
-
OrchResponse
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/test/dispatcher_test.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Dynflow
|
4
|
-
|
5
|
-
describe Dispatcher do
|
6
|
-
class Promotion < Action
|
7
|
-
|
8
|
-
def plan(repo_names, package_names)
|
9
|
-
repo_names.each do |repo_name|
|
10
|
-
plan_action(CloneRepo, {'name' => repo_name})
|
11
|
-
end
|
12
|
-
|
13
|
-
package_names.each do |package_name|
|
14
|
-
plan_action(ClonePackage, {'name' => package_name})
|
15
|
-
end
|
16
|
-
|
17
|
-
plan_self('actions' => repo_names.size + package_names.size)
|
18
|
-
end
|
19
|
-
|
20
|
-
input_format do
|
21
|
-
param :actions, Integer
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
class PromotionObserver < Action
|
27
|
-
|
28
|
-
def self.subscribe
|
29
|
-
Promotion
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
class CloneRepo < Action
|
35
|
-
|
36
|
-
input_format do
|
37
|
-
param :name, String
|
38
|
-
end
|
39
|
-
|
40
|
-
output_format do
|
41
|
-
param :id, String
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
class ClonePackage < Action
|
47
|
-
|
48
|
-
input_format do
|
49
|
-
param :name, String
|
50
|
-
end
|
51
|
-
|
52
|
-
output_format do
|
53
|
-
param :id, String
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
class UpdateIndex < Action
|
59
|
-
|
60
|
-
def self.subscribe
|
61
|
-
ClonePackage
|
62
|
-
end
|
63
|
-
|
64
|
-
def plan(input)
|
65
|
-
plan_action(YetAnotherAction, {'hello' => 'world'})
|
66
|
-
super
|
67
|
-
end
|
68
|
-
|
69
|
-
output_format do
|
70
|
-
param :indexed_name, String
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
class YetAnotherAction < Action
|
76
|
-
|
77
|
-
input_format do
|
78
|
-
param :name, String
|
79
|
-
param :hello, String
|
80
|
-
end
|
81
|
-
|
82
|
-
output_format do
|
83
|
-
param :hello, String
|
84
|
-
end
|
85
|
-
|
86
|
-
def plan(arg)
|
87
|
-
plan_self(input.merge(arg))
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
it "builds the execution plan" do
|
93
|
-
execution_plan = Promotion.plan(['zoo', 'foo'], ['elephant'])
|
94
|
-
expected_plan =
|
95
|
-
[
|
96
|
-
[CloneRepo, {'name' => 'zoo'}],
|
97
|
-
[CloneRepo, {'name' => 'foo'}],
|
98
|
-
[ClonePackage, {'name' => 'elephant'}],
|
99
|
-
[YetAnotherAction, {'name' => 'elephant', 'hello' => 'world'}],
|
100
|
-
[UpdateIndex, {'name' => 'elephant'}],
|
101
|
-
[Promotion, {'actions' => 3 }],
|
102
|
-
[PromotionObserver, {'actions' => 3 }]
|
103
|
-
]
|
104
|
-
execution_plan.must_equal expected_plan
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
end
|