bumbleworks 0.0.54 → 0.0.55
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/lib/bumbleworks.rb +1 -0
- data/lib/bumbleworks/process.rb +8 -6
- data/lib/bumbleworks/tracker.rb +53 -0
- data/lib/bumbleworks/version.rb +1 -1
- data/spec/fixtures/trackers.rb +85 -0
- data/spec/lib/bumbleworks/process_spec.rb +26 -9
- data/spec/lib/bumbleworks/tracker_spec.rb +137 -0
- metadata +9 -4
data/lib/bumbleworks.rb
CHANGED
data/lib/bumbleworks/process.rb
CHANGED
@@ -18,7 +18,7 @@ module Bumbleworks
|
|
18
18
|
return nil unless process_status
|
19
19
|
workitems = leaves.map(&:applied_workitem).map { |wi| Bumbleworks::Workitem.new(wi) }
|
20
20
|
if workitems.map(&:entity_fields).uniq.length == 1
|
21
|
-
workitems.first.entity
|
21
|
+
workitems.first.entity if workitems.first.has_entity?
|
22
22
|
else
|
23
23
|
raise EntityConflict
|
24
24
|
end
|
@@ -29,17 +29,19 @@ module Bumbleworks
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def trackers
|
32
|
-
Bumbleworks.dashboard.get_trackers.
|
32
|
+
Bumbleworks.dashboard.get_trackers.select { |tid, attrs|
|
33
33
|
attrs['msg']['fei'] && attrs['msg']['fei']['wfid'] == id
|
34
|
+
}.map { |tid, original_hash|
|
35
|
+
Bumbleworks::Tracker.new(tid, original_hash)
|
34
36
|
}
|
35
37
|
end
|
36
38
|
|
37
39
|
def all_subscribed_tags
|
38
|
-
|
39
|
-
if t
|
40
|
-
|
40
|
+
trackers.inject({ :global => [] }) do |memo, t|
|
41
|
+
if t.global?
|
42
|
+
memo[:global].concat t.tags
|
41
43
|
else
|
42
|
-
(memo[t
|
44
|
+
(memo[t.wfid] ||= []).concat t.tags
|
43
45
|
end
|
44
46
|
memo
|
45
47
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Bumbleworks
|
2
|
+
class Tracker
|
3
|
+
attr_reader :id, :original_hash
|
4
|
+
|
5
|
+
def initialize(id, original_hash = nil)
|
6
|
+
@id = id
|
7
|
+
@original_hash = original_hash || Bumbleworks.dashboard.get_trackers[id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def wfid
|
11
|
+
wfid = fei ? fei['wfid'] : @original_hash['wfid']
|
12
|
+
end
|
13
|
+
|
14
|
+
def process
|
15
|
+
if wfid_from_hash = wfid
|
16
|
+
Bumbleworks::Process.new(wfid_from_hash)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def global?
|
21
|
+
@original_hash['wfid'].nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def conditions
|
25
|
+
@original_hash['conditions'] || {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def tags
|
29
|
+
[conditions['tag']].flatten.compact
|
30
|
+
end
|
31
|
+
|
32
|
+
def action
|
33
|
+
@original_hash['action']
|
34
|
+
end
|
35
|
+
|
36
|
+
def waiting_expression
|
37
|
+
return nil unless fei
|
38
|
+
process.expressions.detect { |e| e.fei.expid == fei['expid'] }.tree
|
39
|
+
end
|
40
|
+
|
41
|
+
def where_clause
|
42
|
+
we = waiting_expression
|
43
|
+
return nil unless we
|
44
|
+
we[1]['where']
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def fei
|
50
|
+
@original_hash['msg']['fei']
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/bumbleworks/version.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
def fake_trackers
|
2
|
+
{
|
3
|
+
"on_error" => {
|
4
|
+
"wfid" => nil,
|
5
|
+
"action" => "error_intercepted",
|
6
|
+
"id" => "on_error",
|
7
|
+
"conditions" => nil,
|
8
|
+
"msg" => {
|
9
|
+
"action" => "launch",
|
10
|
+
"wfid" => "replace",
|
11
|
+
"tree" => [ "define", {}, [["error_dispatcher",{},[]]] ],
|
12
|
+
"workitem" => "replace",
|
13
|
+
"variables" => "compile"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"global_tracker" => {
|
17
|
+
"wfid" => nil,
|
18
|
+
"action" => "left_tag",
|
19
|
+
"id" => "global_tracker",
|
20
|
+
"conditions" => { "tag" => [ "the_event" ] },
|
21
|
+
"msg" => {
|
22
|
+
"action" => "reply",
|
23
|
+
"fei" => {
|
24
|
+
"engine_id" => "engine",
|
25
|
+
"wfid" => "my_wfid",
|
26
|
+
"subid" => "dc6cff8c33746836353224d7b3d10b4b",
|
27
|
+
"expid" => "0_0_0"
|
28
|
+
},
|
29
|
+
"workitem" => "replace",
|
30
|
+
"flavour" => "await"
|
31
|
+
}
|
32
|
+
},
|
33
|
+
"local_tracker" => {
|
34
|
+
"wfid" => "my_wfid",
|
35
|
+
"action" => "left_tag",
|
36
|
+
"id" => "local_tracker",
|
37
|
+
"conditions" => { "tag" => [ "local_event" ] },
|
38
|
+
"msg" => {
|
39
|
+
"action" => "reply",
|
40
|
+
"fei" => {
|
41
|
+
"engine_id" => "engine",
|
42
|
+
"wfid" => "my_wfid",
|
43
|
+
"subid" => "8cb9de101dbc38e3f375a277d025c170",
|
44
|
+
"expid" => "0_0_1"
|
45
|
+
},
|
46
|
+
"workitem" => "replace",
|
47
|
+
"flavour" => "await"
|
48
|
+
}
|
49
|
+
},
|
50
|
+
"local_error_intercept" => {
|
51
|
+
"wfid" => "my_wfid",
|
52
|
+
"action" => "error_intercepted",
|
53
|
+
"id" => "local_error_intercept",
|
54
|
+
"conditions" => { "message" => [ "/bad/" ] },
|
55
|
+
"msg" => {
|
56
|
+
"action" => "reply",
|
57
|
+
"fei" => {
|
58
|
+
"engine_id" => "engine",
|
59
|
+
"wfid" => "my_wfid",
|
60
|
+
"subid" => "e4bb9b945b829019b9f1fcd266fb5bd8",
|
61
|
+
"expid" => "0_0_2"
|
62
|
+
},
|
63
|
+
"workitem" => "replace",
|
64
|
+
"flavour" => "await"
|
65
|
+
}
|
66
|
+
},
|
67
|
+
"participant_tracker" => {
|
68
|
+
"wfid" => "my_wfid",
|
69
|
+
"action" => "dispatch",
|
70
|
+
"id" => "participant_tracker",
|
71
|
+
"conditions" => { "participant_name" => [ "goose", "bunnies" ] },
|
72
|
+
"msg" => {
|
73
|
+
"action" => "reply",
|
74
|
+
"fei" => {
|
75
|
+
"engine_id" => "engine",
|
76
|
+
"wfid" => "my_wfid",
|
77
|
+
"subid" => "6ddfe62d9aa2a25d8928de987c24caf1",
|
78
|
+
"expid" => "0_0_3"
|
79
|
+
},
|
80
|
+
"workitem" => "replace",
|
81
|
+
"flavour" => "await"
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
@@ -11,6 +11,7 @@ describe Bumbleworks::Process do
|
|
11
11
|
concurrence do
|
12
12
|
wait_for_event :an_invitation
|
13
13
|
await :left_tag => 'a_friend'
|
14
|
+
await :participant => 'some_darling_cat'
|
14
15
|
end
|
15
16
|
end
|
16
17
|
Bumbleworks.define_process 'straightening_the_rocks' do
|
@@ -19,6 +20,9 @@ describe Bumbleworks::Process do
|
|
19
20
|
wait_for_event :speedos
|
20
21
|
end
|
21
22
|
end
|
23
|
+
Bumbleworks.define_process 'i_wait_for_nobody' do
|
24
|
+
tough_guy :task => 'blow_this_thing_wide_open'
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
describe '.new' do
|
@@ -47,13 +51,13 @@ describe Bumbleworks::Process do
|
|
47
51
|
it 'lists all trackers this process is waiting on' do
|
48
52
|
bp1 = Bumbleworks.launch!('going_to_the_dance')
|
49
53
|
bp2 = Bumbleworks.launch!('straightening_the_rocks')
|
50
|
-
wait_until { bp1.trackers.count ==
|
51
|
-
bp1.trackers.map { |t| t
|
52
|
-
bp2.trackers.map { |t| t
|
53
|
-
bp1.trackers.map { |t| t
|
54
|
-
bp2.trackers.map { |t| t
|
55
|
-
bp1.trackers.map { |t| t
|
56
|
-
bp2.trackers.map { |t| t
|
54
|
+
wait_until { bp1.trackers.count == 3 && bp2.trackers.count == 2 }
|
55
|
+
bp1.trackers.map { |t| t.process }.should == [bp1, bp1, bp1]
|
56
|
+
bp2.trackers.map { |t| t.process }.should == [bp2, bp2]
|
57
|
+
bp1.trackers.map { |t| t.action }.should == ['left_tag', 'left_tag', 'dispatch']
|
58
|
+
bp2.trackers.map { |t| t.action }.should == ['left_tag', 'left_tag']
|
59
|
+
bp1.trackers.map { |t| t.conditions['tag'] }.should == [['an_invitation'], ['a_friend'], nil]
|
60
|
+
bp2.trackers.map { |t| t.conditions['tag'] }.should == [['rock_caliper_delivery'], ['speedos']]
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -61,20 +65,32 @@ describe Bumbleworks::Process do
|
|
61
65
|
it 'lists all tags this process is waiting on' do
|
62
66
|
bp1 = Bumbleworks.launch!('going_to_the_dance')
|
63
67
|
bp2 = Bumbleworks.launch!('straightening_the_rocks')
|
64
|
-
wait_until { bp1.trackers.count ==
|
68
|
+
wait_until { bp1.trackers.count == 3 && bp2.trackers.count == 2 }
|
65
69
|
bp1.all_subscribed_tags.should == { :global => ['an_invitation'], bp1.wfid => ['a_friend'] }
|
66
70
|
bp2.all_subscribed_tags.should == { :global => ['rock_caliper_delivery', 'speedos'] }
|
67
71
|
end
|
72
|
+
|
73
|
+
it 'sets global tags to empty array by default' do
|
74
|
+
bp = Bumbleworks.launch!('i_wait_for_nobody')
|
75
|
+
wait_until { bp.tasks.count == 1 }
|
76
|
+
bp.all_subscribed_tags.should == { :global => [] }
|
77
|
+
end
|
68
78
|
end
|
69
79
|
|
70
80
|
describe '#subscribed_events' do
|
71
81
|
it 'lists all events (global tags) this process is waiting on' do
|
72
82
|
bp1 = Bumbleworks.launch!('going_to_the_dance')
|
73
83
|
bp2 = Bumbleworks.launch!('straightening_the_rocks')
|
74
|
-
wait_until { bp1.trackers.count ==
|
84
|
+
wait_until { bp1.trackers.count == 3 && bp2.trackers.count == 2 }
|
75
85
|
bp1.subscribed_events.should == ['an_invitation']
|
76
86
|
bp2.subscribed_events.should == ['rock_caliper_delivery', 'speedos']
|
77
87
|
end
|
88
|
+
|
89
|
+
it 'returns empty array if no global tags' do
|
90
|
+
bp = Bumbleworks.launch!('i_wait_for_nobody')
|
91
|
+
wait_until { bp.tasks.count == 1 }
|
92
|
+
bp.subscribed_events.should == []
|
93
|
+
end
|
78
94
|
end
|
79
95
|
|
80
96
|
describe '#is_waiting_for?' do
|
@@ -156,6 +172,7 @@ describe Bumbleworks::Process do
|
|
156
172
|
|
157
173
|
it 'returns nil if no entity' do
|
158
174
|
bp = Bumbleworks.launch!('going_to_the_dance')
|
175
|
+
wait_until { bp.trackers.count > 0 }
|
159
176
|
bp.entity.should be_nil
|
160
177
|
end
|
161
178
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.expand_path(File.join(fixtures_path, 'entities', 'rainbow_loom'))
|
2
|
+
require File.expand_path(File.join(fixtures_path, 'trackers'))
|
3
|
+
|
4
|
+
describe Bumbleworks::Tracker do
|
5
|
+
before(:each) do
|
6
|
+
Bumbleworks.reset!
|
7
|
+
Bumbleworks.storage = {}
|
8
|
+
Bumbleworks.dashboard.stub(:get_trackers => fake_trackers)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it 'sets tracker id and fetches original_hash from dashboard' do
|
13
|
+
tr = described_class.new('global_tracker')
|
14
|
+
tr.id.should == 'global_tracker'
|
15
|
+
tr.original_hash.should == fake_trackers['global_tracker']
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets tracker id and original_hash if directly provided' do
|
19
|
+
tr = described_class.new('global_tracker', 'snarfles')
|
20
|
+
tr.id.should == 'global_tracker'
|
21
|
+
tr.original_hash.should == 'snarfles'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#wfid' do
|
26
|
+
it 'returns wfid from original hash' do
|
27
|
+
described_class.new('local_tracker').wfid.should == 'my_wfid'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns wfid from flow expression for global trackers' do
|
31
|
+
described_class.new('global_tracker').wfid.should == 'my_wfid'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns nil if no wfid' do
|
35
|
+
described_class.new('on_error').wfid.should be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#process' do
|
40
|
+
it 'returns process for wfid stored in msg' do
|
41
|
+
tr = described_class.new('global_tracker')
|
42
|
+
tr.process.should == Bumbleworks::Process.new('my_wfid')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns nil if no wfid' do
|
46
|
+
tr = described_class.new('on_error')
|
47
|
+
tr.process.should be_nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#global?' do
|
52
|
+
it 'returns true if not listening to events on a specific wfid' do
|
53
|
+
described_class.new('on_error').global?.should be_true
|
54
|
+
described_class.new('global_tracker').global?.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns false if listening to events on a specific wfid' do
|
58
|
+
described_class.new('local_tracker').global?.should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#conditions' do
|
63
|
+
it 'returns conditions that this tracker is watching' do
|
64
|
+
described_class.new('global_tracker').conditions.should == { "tag" => [ "the_event" ] }
|
65
|
+
described_class.new('local_tracker').conditions.should == { "tag" => [ "local_event" ] }
|
66
|
+
described_class.new('local_error_intercept').conditions.should == { "message" => [ "/bad/" ] }
|
67
|
+
described_class.new('participant_tracker').conditions.should == { "participant_name" => [ "goose","bunnies" ] }
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns empty hash when no conditions' do
|
71
|
+
described_class.new('on_error').conditions.should == {}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#tags' do
|
76
|
+
it 'returns array of tags' do
|
77
|
+
described_class.new('global_tracker').tags.should == [ "the_event" ]
|
78
|
+
described_class.new('local_tracker').tags.should == [ "local_event" ]
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns empty array if no tags' do
|
82
|
+
described_class.new('local_error_intercept').tags.should == []
|
83
|
+
described_class.new('participant_tracker').tags.should == []
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#action' do
|
88
|
+
it 'returns action being awaited' do
|
89
|
+
described_class.new('global_tracker').action.should == 'left_tag'
|
90
|
+
described_class.new('local_error_intercept').action.should == 'error_intercepted'
|
91
|
+
described_class.new('participant_tracker').action.should == 'dispatch'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#waiting_expression' do
|
96
|
+
it 'returns nil when no expression is waiting' do
|
97
|
+
described_class.new('on_error').waiting_expression.should be_nil
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns expression awaiting reply' do
|
101
|
+
process = Bumbleworks::Process.new('my_wfid')
|
102
|
+
expression1 = double(:fei => double(:expid => '0_0_0'), :tree => :a_global_expression)
|
103
|
+
expression2 = double(:fei => double(:expid => '0_0_1'), :tree => :a_local_expression)
|
104
|
+
process.stub(:expressions => [expression1, expression2])
|
105
|
+
|
106
|
+
tracker1 = described_class.new('global_tracker')
|
107
|
+
tracker1.stub(:process => process)
|
108
|
+
tracker1.waiting_expression.should == :a_global_expression
|
109
|
+
|
110
|
+
tracker2 = described_class.new('local_tracker')
|
111
|
+
tracker2.stub(:process => process)
|
112
|
+
tracker2.waiting_expression.should == :a_local_expression
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#where_clause' do
|
117
|
+
it 'returns where clause from waiting expression' do
|
118
|
+
tracker = described_class.new('global_tracker')
|
119
|
+
tracker.stub(:waiting_expression => [
|
120
|
+
'wait_for_event', { "where" => "some_stuff_matches" }, []
|
121
|
+
])
|
122
|
+
tracker.where_clause.should == 'some_stuff_matches'
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns nil when waiting_expression does not include where clause' do
|
126
|
+
tracker = described_class.new('global_tracker')
|
127
|
+
tracker.stub(:waiting_expression => [
|
128
|
+
'wait_for_event', {}, []
|
129
|
+
])
|
130
|
+
tracker.where_clause.should be_nil
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'returns nil when no waiting_expression' do
|
134
|
+
described_class.new('on_error').where_clause.should be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bumbleworks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.55
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-01-
|
15
|
+
date: 2014-01-14 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: ruote
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- lib/bumbleworks/task.rb
|
191
191
|
- lib/bumbleworks/task/base.rb
|
192
192
|
- lib/bumbleworks/task/finder.rb
|
193
|
+
- lib/bumbleworks/tracker.rb
|
193
194
|
- lib/bumbleworks/tree_builder.rb
|
194
195
|
- lib/bumbleworks/version.rb
|
195
196
|
- lib/bumbleworks/workitem.rb
|
@@ -211,6 +212,7 @@ files:
|
|
211
212
|
- spec/fixtures/definitions/nested_folder/test_nested_process.rb
|
212
213
|
- spec/fixtures/definitions/test_process.rb
|
213
214
|
- spec/fixtures/entities/rainbow_loom.rb
|
215
|
+
- spec/fixtures/trackers.rb
|
214
216
|
- spec/integration/entity_spec.rb
|
215
217
|
- spec/integration/example_configurations_spec.rb
|
216
218
|
- spec/integration/history_storage_spec.rb
|
@@ -235,6 +237,7 @@ files:
|
|
235
237
|
- spec/lib/bumbleworks/support_spec.rb
|
236
238
|
- spec/lib/bumbleworks/task/finder_spec.rb
|
237
239
|
- spec/lib/bumbleworks/task_spec.rb
|
240
|
+
- spec/lib/bumbleworks/tracker_spec.rb
|
238
241
|
- spec/lib/bumbleworks/tree_builder_spec.rb
|
239
242
|
- spec/lib/bumbleworks/workitem_entity_storage_spec.rb
|
240
243
|
- spec/lib/bumbleworks/workitem_spec.rb
|
@@ -258,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
258
261
|
version: '0'
|
259
262
|
segments:
|
260
263
|
- 0
|
261
|
-
hash:
|
264
|
+
hash: 2137363993883985375
|
262
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
263
266
|
none: false
|
264
267
|
requirements:
|
@@ -267,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
270
|
version: '0'
|
268
271
|
segments:
|
269
272
|
- 0
|
270
|
-
hash:
|
273
|
+
hash: 2137363993883985375
|
271
274
|
requirements: []
|
272
275
|
rubyforge_project:
|
273
276
|
rubygems_version: 1.8.23
|
@@ -291,6 +294,7 @@ test_files:
|
|
291
294
|
- spec/fixtures/definitions/nested_folder/test_nested_process.rb
|
292
295
|
- spec/fixtures/definitions/test_process.rb
|
293
296
|
- spec/fixtures/entities/rainbow_loom.rb
|
297
|
+
- spec/fixtures/trackers.rb
|
294
298
|
- spec/integration/entity_spec.rb
|
295
299
|
- spec/integration/example_configurations_spec.rb
|
296
300
|
- spec/integration/history_storage_spec.rb
|
@@ -315,6 +319,7 @@ test_files:
|
|
315
319
|
- spec/lib/bumbleworks/support_spec.rb
|
316
320
|
- spec/lib/bumbleworks/task/finder_spec.rb
|
317
321
|
- spec/lib/bumbleworks/task_spec.rb
|
322
|
+
- spec/lib/bumbleworks/tracker_spec.rb
|
318
323
|
- spec/lib/bumbleworks/tree_builder_spec.rb
|
319
324
|
- spec/lib/bumbleworks/workitem_entity_storage_spec.rb
|
320
325
|
- spec/lib/bumbleworks/workitem_spec.rb
|