rworkflow 0.6.5 → 0.7.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.
@@ -9,14 +9,14 @@ module Rworkflow
9
9
 
10
10
  def test_workflow
11
11
  lifecycle = Lifecycle.new do |lc|
12
- lc.state("State1", {cardinality: 2}) do |state|
12
+ lc.state('State1', cardinality: 2) do |state|
13
13
  state.transition :pushed, Flow::STATE_SUCCESSFUL
14
14
  state.transition :failed, Flow::STATE_FAILED
15
15
  end
16
16
 
17
- lc.initial = "State1"
17
+ lc.initial = 'State1'
18
18
  end
19
- initial_objects = [1,2,3]
19
+ initial_objects = [1, 2, 3]
20
20
  workflow = Flow.create(lifecycle, 'myWorkflow')
21
21
  workflow_id = workflow.id
22
22
 
@@ -44,21 +44,21 @@ module Rworkflow
44
44
  end
45
45
 
46
46
  assert workflow.finished?
47
- counters = workflow.get_counters
47
+ counters = workflow.counters
48
48
  assert_equal 2, counters[Flow::STATE_SUCCESSFUL]
49
49
  assert_equal 1, counters[Flow::STATE_FAILED]
50
50
 
51
- assert_equal [1,3], workflow.list_objects(Flow::STATE_SUCCESSFUL)
51
+ assert_equal [1, 3], workflow.list_objects(Flow::STATE_SUCCESSFUL)
52
52
  end
53
53
 
54
54
  def test_flow_cardinality_all_started
55
55
  lifecycle = Lifecycle.new do |lc|
56
- lc.state("State1", {cardinality: Lifecycle::CARDINALITY_ALL_STARTED}) do |state|
56
+ lc.state('State1', cardinality: Lifecycle::CARDINALITY_ALL_STARTED) do |state|
57
57
  state.transition :pushed, Flow::STATE_SUCCESSFUL
58
58
  state.transition :failed, Flow::STATE_FAILED
59
59
  end
60
60
 
61
- lc.initial = "State1"
61
+ lc.initial = 'State1'
62
62
  end
63
63
 
64
64
  initial_objects = (1..6).to_a
@@ -70,17 +70,17 @@ module Rworkflow
70
70
  end
71
71
 
72
72
  def test_flow_state_policy_wait
73
- initial_objects = [1,2,3,4]
73
+ initial_objects = [1, 2, 3, 4]
74
74
  lifecycle = Lifecycle.new do |lc|
75
- lc.state("InitState", {cardinality: 1}) do |state|
76
- state.transition :pushed, "WaitState"
75
+ lc.state('InitState', cardinality: 1) do |state|
76
+ state.transition :pushed, 'WaitState'
77
77
  end
78
78
 
79
- lc.state("WaitState", {cardinality: initial_objects.size, priority: State::DEFAULT_PRIORITY, policy: State::STATE_POLICY_WAIT}) do |state|
79
+ lc.state('WaitState', cardinality: initial_objects.size, policy: State::STATE_POLICY_WAIT) do |state|
80
80
  state.transition :collected, Flow::STATE_SUCCESSFUL
81
81
  end
82
82
 
83
- lc.initial = "InitState"
83
+ lc.initial = 'InitState'
84
84
  end
85
85
 
86
86
  workflow = Flow.create(lifecycle, 'myWorkflow')
@@ -93,7 +93,7 @@ module Rworkflow
93
93
  end
94
94
  end
95
95
 
96
- workflow.fetch(1, 'WaitState') do |objects|
96
+ workflow.fetch(1, 'WaitState') do |_objects|
97
97
  # This block should not be executed
98
98
  assert false, 'The collector state should not be executed until there is enough waiting objects (>= cardinality)'
99
99
  end
@@ -9,7 +9,7 @@ module Rworkflow
9
9
 
10
10
  def test_definition
11
11
  lifecycle = Lifecycle.new do |lc|
12
- lc.state("State1") do |state|
12
+ lc.state('State1') do |state|
13
13
  state.transition :pushed, :successful
14
14
  end
15
15
 
@@ -17,22 +17,22 @@ module Rworkflow
17
17
  end
18
18
 
19
19
  assert_equal 'State1', lifecycle.initial
20
- assert_equal :successful, lifecycle.transition("State1", :pushed)
21
- assert_raises(Rworkflow::StateError) { lifecycle.transition("UnexistingState", :pushed) }
22
- assert_raises(Rworkflow::TransitionError) { lifecycle.transition("State1", :non_existing_transition) }
20
+ assert_equal :successful, lifecycle.transition('State1', :pushed)
21
+ assert_raises(Rworkflow::StateError) { lifecycle.transition('UnexistingState', :pushed) }
22
+ assert_raises(Rworkflow::TransitionError) { lifecycle.transition('State1', :non_existing_transition) }
23
23
 
24
24
  lifecycle.default = Rworkflow::Flow::STATE_FAILED
25
25
  assert_equal Rworkflow::Flow::STATE_FAILED, lifecycle.default
26
- assert_equal Rworkflow::Flow::STATE_FAILED, lifecycle.transition("State1", :non_existing_transition)
26
+ assert_equal Rworkflow::Flow::STATE_FAILED, lifecycle.transition('State1', :non_existing_transition)
27
27
  end
28
28
 
29
29
  def test_serialization
30
30
  lifecycle = Lifecycle.new do |lc|
31
- lc.state("State1") do |state|
31
+ lc.state('State1') do |state|
32
32
  state.transition :pushed, :successful
33
33
  end
34
34
 
35
- lc.initial = "State1"
35
+ lc.initial = 'State1'
36
36
  end
37
37
 
38
38
  serialized = lifecycle.serialize
@@ -40,21 +40,21 @@ module Rworkflow
40
40
  unserialized = Lifecycle.unserialize(serialized)
41
41
 
42
42
  assert_equal lifecycle.initial, unserialized.initial
43
- assert_equal Set.new(lifecycle.states.keys), Set.new(unserialized.states.keys)
44
- assert lifecycle.states.all? {|name, state| unserialized.states[name].instance_eval{@transitions} == state.instance_eval{@transitions} }
43
+ assert_equal Set.new(lifecycle.states.keys), Set.new(unserialized.states.keys)
44
+ assert lifecycle.states.all? { |name, state| unserialized.states[name].instance_eval { @transitions } == state.instance_eval { @transitions } }
45
45
  end
46
46
 
47
47
  def test_concat
48
- lifecycle_one = LCFactory.simple_lifecycle("1", :next)
49
- lifecycle_two = LCFactory.simple_lifecycle("2", :finish)
48
+ lifecycle_one = LCFactory.simple_lifecycle('1', :next)
49
+ lifecycle_two = LCFactory.simple_lifecycle('2', :finish)
50
50
 
51
- lifecycle_one.concat!("1", :next, lifecycle_two)
51
+ lifecycle_one.concat!('1', :next, lifecycle_two)
52
52
 
53
53
  assert_equal '1', lifecycle_one.initial
54
- assert_equal '2', lifecycle_one.transition("1", :next)
55
- assert_equal SidekiqFlow::STATE_SUCCESSFUL, lifecycle_one.transition("2", :finish)
54
+ assert_equal '2', lifecycle_one.transition('1', :next)
55
+ assert_equal SidekiqFlow::STATE_SUCCESSFUL, lifecycle_one.transition('2', :finish)
56
56
 
57
- lifecycle_three = LCFactory.simple_lifecycle("3", :finish)
57
+ lifecycle_three = LCFactory.simple_lifecycle('3', :finish)
58
58
  lifecycle_three.state('1') do |s|
59
59
  s.transition(:next, '3')
60
60
  s.transition(:prev, '2')
@@ -67,9 +67,9 @@ module Rworkflow
67
67
  end
68
68
 
69
69
  class LCFactory
70
- def self.simple_lifecycle(state_name, transition, cardinality = 1, priority = nil)
70
+ def self.simple_lifecycle(state_name, transition, cardinality = 1)
71
71
  return Rworkflow::Lifecycle.new do |cycle|
72
- cycle.state(state_name, cardinality: cardinality, priority: priority) do |state|
72
+ cycle.state(state_name, cardinality: cardinality) do |state|
73
73
  state.transition transition, Rworkflow::SidekiqFlow::STATE_SUCCESSFUL
74
74
  state.transition :failed, Rworkflow::SidekiqFlow::STATE_FAILED
75
75
  end
@@ -9,20 +9,20 @@ module Rworkflow
9
9
 
10
10
  def test_lethal_workflow
11
11
  lifecycle = Lifecycle.new do |lc|
12
- lc.state("Rworkflow::SidekiqFlowTest::Floating", {CARDINALITY_ALL_STARTEDality: 10}) do |state|
12
+ lc.state('Rworkflow::SidekiqFlowTest::Floating', cardinality: 10) do |state|
13
13
  state.transition :rescued, 'Rworkflow::SidekiqFlowTest::Lifeboat'
14
14
  state.transition :drowned, Rworkflow::Flow::STATE_FAILED
15
15
  end
16
- lc.state("Rworkflow::SidekiqFlowTest::Lifeboat", {cardinality: 2}) do |state|
16
+ lc.state('Rworkflow::SidekiqFlowTest::Lifeboat', cardinality: 2) do |state|
17
17
  state.transition :landed, 'Rworkflow::SidekiqFlowTest::Land'
18
18
  state.transition :starved, Rworkflow::Flow::STATE_FAILED
19
19
  end
20
- lc.state("Rworkflow::SidekiqFlowTest::Land") do |state|
20
+ lc.state('Rworkflow::SidekiqFlowTest::Land') do |state|
21
21
  state.transition :rescued, Rworkflow::Flow::STATE_SUCCESSFUL
22
22
  state.transition :died, Rworkflow::Flow::STATE_FAILED
23
23
  end
24
24
 
25
- lc.initial = "Rworkflow::SidekiqFlowTest::Floating"
25
+ lc.initial = 'Rworkflow::SidekiqFlowTest::Floating'
26
26
  end
27
27
 
28
28
  initial_objects = (0...20).to_a
@@ -30,27 +30,27 @@ module Rworkflow
30
30
  workflow.start(initial_objects)
31
31
 
32
32
  assert workflow.finished?
33
- counters = workflow.get_counters
33
+ counters = workflow.counters
34
34
  assert_equal 19, counters[Rworkflow::Flow::STATE_FAILED]
35
35
  assert_equal 1, counters[Rworkflow::Flow::STATE_SUCCESSFUL]
36
36
 
37
- assert 2, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Floating").get.to_i
38
- assert 6, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Lifeboat").get.to_i
39
- assert 2, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Land").get.to_i
37
+ assert 2, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Floating').get.to_i
38
+ assert 6, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Lifeboat').get.to_i
39
+ assert 2, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Land').get.to_i
40
40
  end
41
41
 
42
42
  def test_pause_continue
43
43
  lifecycle = Lifecycle.new do |lc|
44
- lc.state("Rworkflow::SidekiqFlowTest::Floating", {cardinality: 10}) do |state|
44
+ lc.state('Rworkflow::SidekiqFlowTest::Floating', cardinality: 10) do |state|
45
45
  state.transition :rescued, 'Rworkflow::SidekiqFlowTest::Lifeboat'
46
46
  state.transition :drowned, Rworkflow::Flow::STATE_FAILED
47
47
  end
48
- lc.state("Rworkflow::SidekiqFlowTest::Lifeboat", {cardinality: 2}) do |state|
48
+ lc.state('Rworkflow::SidekiqFlowTest::Lifeboat', cardinality: 2) do |state|
49
49
  state.transition :landed, Rworkflow::Flow::STATE_SUCCESSFUL
50
50
  state.transition :starved, Rworkflow::Flow::STATE_FAILED
51
51
  end
52
52
 
53
- lc.initial = "Rworkflow::SidekiqFlowTest::Floating"
53
+ lc.initial = 'Rworkflow::SidekiqFlowTest::Floating'
54
54
  end
55
55
 
56
56
  initial_objects = (0...20).to_a
@@ -65,25 +65,25 @@ module Rworkflow
65
65
  workflow.continue
66
66
  assert workflow.finished?
67
67
 
68
- counters = workflow.get_counters
68
+ counters = workflow.counters
69
69
  assert_equal 18, counters[Rworkflow::Flow::STATE_FAILED]
70
70
  assert_equal 2, counters[Rworkflow::Flow::STATE_SUCCESSFUL]
71
71
 
72
- assert 2, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Floating").get.to_i
73
- assert 6, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Lifeboat").get.to_i
72
+ assert 2, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Floating').get.to_i
73
+ assert 6, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Lifeboat').get.to_i
74
74
  end
75
75
 
76
76
  def test_collector_state_workflow
77
77
  lifecycle = Lifecycle.new do |lc|
78
- lc.state("Rworkflow::SidekiqFlowTest::PostcardSend", {cardinality: 1}) do |state|
78
+ lc.state('Rworkflow::SidekiqFlowTest::PostcardSend', cardinality: 1) do |state|
79
79
  state.transition :sent, 'Rworkflow::SidekiqFlowTest::PostcardCollector'
80
80
  end
81
81
 
82
- lc.state("Rworkflow::SidekiqFlowTest::PostcardCollector", {cardinality: Lifecycle::CARDINALITY_ALL_STARTED, priority: State::DEFAULT_PRIORITY, policy: State::STATE_POLICY_WAIT}) do |state|
82
+ lc.state('Rworkflow::SidekiqFlowTest::PostcardCollector', cardinality: Lifecycle::CARDINALITY_ALL_STARTED, policy: State::STATE_POLICY_WAIT) do |state|
83
83
  state.transition :received, Rworkflow::Flow::STATE_SUCCESSFUL
84
84
  end
85
85
 
86
- lc.initial = "Rworkflow::SidekiqFlowTest::PostcardSend"
86
+ lc.initial = 'Rworkflow::SidekiqFlowTest::PostcardSend'
87
87
  end
88
88
 
89
89
  initial_objects = (0...20).to_a
@@ -91,24 +91,24 @@ module Rworkflow
91
91
  workflow.start(initial_objects)
92
92
 
93
93
  assert workflow.finished?, 'Rworkflow finish successfully'
94
- assert_equal 20, RedisRds::String.new("Rworkflow::SidekiqFlowTest::PostcardSend").get.to_i, 'All initial objects should be processed by the first state one by one'
95
- assert_equal 1, RedisRds::String.new("Rworkflow::SidekiqFlowTest::PostcardSend_card").get.to_i, 'All initial objects should be processed by the first state one by one'
96
- assert_equal 1, RedisRds::String.new("Rworkflow::SidekiqFlowTest::PostcardCollector").get.to_i, 'All initial objects should be processed by the collector state all at once'
97
- assert_equal initial_objects.size, RedisRds::String.new("Rworkflow::SidekiqFlowTest::PostcardCollector_card").get.to_i, 'All initial objects should be processed by the collector state all at once'
94
+ assert_equal 20, RedisRds::String.new('Rworkflow::SidekiqFlowTest::PostcardSend').get.to_i, 'All initial objects should be processed by the first state one by one'
95
+ assert_equal 1, RedisRds::String.new('Rworkflow::SidekiqFlowTest::PostcardSend_card').get.to_i, 'All initial objects should be processed by the first state one by one'
96
+ assert_equal 1, RedisRds::String.new('Rworkflow::SidekiqFlowTest::PostcardCollector').get.to_i, 'All initial objects should be processed by the collector state all at once'
97
+ assert_equal initial_objects.size, RedisRds::String.new('Rworkflow::SidekiqFlowTest::PostcardCollector_card').get.to_i, 'All initial objects should be processed by the collector state all at once'
98
98
  end
99
99
 
100
100
  def test_gated
101
101
  lifecycle = Lifecycle.new do |lc|
102
- lc.state("Rworkflow::SidekiqFlowTest::Floating", {cardinality: 10}) do |state|
102
+ lc.state('Rworkflow::SidekiqFlowTest::Floating', cardinality: 10) do |state|
103
103
  state.transition :rescued, 'Rworkflow::SidekiqFlowTest::Lifeboat'
104
104
  state.transition :drowned, Rworkflow::Flow::STATE_FAILED
105
105
  end
106
- lc.state("Rworkflow::SidekiqFlowTest::Lifeboat", {cardinality: 2, policy: SidekiqFlow::STATE_POLICY_GATED}) do |state|
106
+ lc.state('Rworkflow::SidekiqFlowTest::Lifeboat', cardinality: 2, policy: SidekiqFlow::STATE_POLICY_GATED) do |state|
107
107
  state.transition :landed, Rworkflow::Flow::STATE_SUCCESSFUL
108
108
  state.transition :starved, Rworkflow::Flow::STATE_FAILED
109
109
  end
110
110
 
111
- lc.initial = "Rworkflow::SidekiqFlowTest::Floating"
111
+ lc.initial = 'Rworkflow::SidekiqFlowTest::Floating'
112
112
  end
113
113
 
114
114
  initial_objects = (0...20).to_a
@@ -119,17 +119,17 @@ module Rworkflow
119
119
  workflow.open_gate('Rworkflow::SidekiqFlowTest::Lifeboat')
120
120
  assert workflow.finished?
121
121
 
122
- counters = workflow.get_counters
122
+ counters = workflow.counters
123
123
  assert_equal 18, counters[Rworkflow::Flow::STATE_FAILED]
124
124
  assert_equal 2, counters[Rworkflow::Flow::STATE_SUCCESSFUL]
125
125
 
126
- assert 2, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Floating").get.to_i
127
- assert 6, RedisRds::String.new("Rworkflow::SidekiqFlowTest::Lifeboat").get.to_i
126
+ assert 2, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Floating').get.to_i
127
+ assert 6, RedisRds::String.new('Rworkflow::SidekiqFlowTest::Lifeboat').get.to_i
128
128
  end
129
129
 
130
130
  class Floating < Worker
131
131
  def process(objects)
132
- rescued, drowned = objects.partition { |object| object.even? }
132
+ rescued, drowned = objects.partition(&:even?)
133
133
  transition(:rescued, rescued)
134
134
  transition(:drowned, drowned)
135
135
  RedisRds::String.new(self.class.name).incr
@@ -36,10 +36,6 @@ module Rworkflow
36
36
  other_state.policy = State::STATE_POLICY_WAIT
37
37
  assert_not_equal @state, other_state, 'State A != B: different policies!'
38
38
 
39
- other_state = State.new
40
- other_state.priority = :high
41
- assert_not_equal @state, other_state, 'State A != B: different priorities!'
42
-
43
39
  other_state = State.new
44
40
  other_state.cardinality = 32
45
41
  assert_not_equal @state, other_state, 'State A != B: different cardinalities!'
@@ -74,14 +70,13 @@ module Rworkflow
74
70
  @state.transition('a', 'b')
75
71
  @state.policy = State::STATE_POLICY_WAIT
76
72
  @state.cardinality = 2
77
- @state.priority = :high
78
73
  cloned = @state.clone
79
74
  assert_equal @state, cloned, 'Original and cloned states should be equal'
80
75
  assert !@state.equal?(cloned), 'Original and cloned states should not be the same object'
81
76
  end
82
77
 
83
78
  def test_merge
84
- other_state = State.new(cardinality: 2, priority: :high, policy: State::STATE_POLICY_WAIT)
79
+ other_state = State.new(cardinality: 2, policy: State::STATE_POLICY_WAIT)
85
80
  merged = @state.merge(other_state)
86
81
  assert_equal merged, other_state, 'Merged state should be equal to state B'
87
82
 
@@ -4,10 +4,10 @@ ENV['RAILS_ENV'] = 'test'
4
4
  require 'simplecov'
5
5
  require 'coveralls'
6
6
 
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
8
  SimpleCov::Formatter::HTMLFormatter,
9
9
  Coveralls::SimpleCov::Formatter
10
- ]
10
+ ])
11
11
  SimpleCov.start
12
12
 
13
13
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rworkflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - barcoo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
- description: 'TBC: Description of Rworkflow.'
69
+ description: rworkflow - workflow framework for Ruby
70
70
  email:
71
71
  - roots@checkitmobile.com
72
72
  executables: []
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - MIT-LICENSE
77
+ - README.md
77
78
  - Rakefile
78
79
  - lib/rworkflow.rb
79
80
  - lib/rworkflow/configuration.rb
@@ -92,7 +93,6 @@ files:
92
93
  - lib/rworkflow/transition_error.rb
93
94
  - lib/rworkflow/version.rb
94
95
  - lib/rworkflow/worker.rb
95
- - lib/tasks/rworkflow_tasks.rake
96
96
  - test/dummy/README.rdoc
97
97
  - test/dummy/Rakefile
98
98
  - test/dummy/app/assets/javascripts/application.js
@@ -129,11 +129,10 @@ files:
129
129
  - test/dummy/public/favicon.ico
130
130
  - test/flow_test.rb
131
131
  - test/lifecycle_test.rb
132
- - test/rworkflow_test.rb
133
132
  - test/sidekiq_flow_test.rb
134
133
  - test/state_test.rb
135
134
  - test/test_helper.rb
136
- homepage: https://www.barcoo.com
135
+ homepage: https://github.com/barcoo/rworkflow
137
136
  licenses:
138
137
  - MIT
139
138
  metadata: {}
@@ -156,7 +155,7 @@ rubyforge_project:
156
155
  rubygems_version: 2.6.10
157
156
  signing_key:
158
157
  specification_version: 4
159
- summary: 'TBC: Summary of Rworkflow.'
158
+ summary: rworkflow - workflow framework for Ruby
160
159
  test_files:
161
160
  - test/dummy/app/assets/javascripts/application.js
162
161
  - test/dummy/app/assets/stylesheets/application.css
@@ -194,7 +193,6 @@ test_files:
194
193
  - test/dummy/README.rdoc
195
194
  - test/flow_test.rb
196
195
  - test/lifecycle_test.rb
197
- - test/rworkflow_test.rb
198
196
  - test/sidekiq_flow_test.rb
199
197
  - test/state_test.rb
200
198
  - test/test_helper.rb
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :rworkflow do
3
- # # Task goes here
4
- # end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RworkflowTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Rworkflow
6
- end
7
- end