bumbleworks 0.0.29 → 0.0.30
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 +8 -8
- data/lib/bumbleworks/ruote.rb +3 -0
- data/lib/bumbleworks/ruote/exp/broadcast_event_expression.rb +17 -0
- data/lib/bumbleworks/ruote/exp/wait_for_event_expression.rb +31 -0
- data/lib/bumbleworks/version.rb +1 -1
- data/spec/lib/bumbleworks/ruote/exp/broadcast_event_expression_spec.rb +24 -0
- data/spec/lib/bumbleworks/ruote/exp/wait_for_event_expression_spec.rb +79 -0
- data/spec/lib/bumbleworks/ruote_spec.rb +20 -12
- data/spec/lib/bumbleworks/task_spec.rb +1 -1
- data/spec/lib/bumbleworks_spec.rb +7 -2
- data/spec/support/tracer.rb +14 -0
- metadata +10 -2
data/lib/bumbleworks.rb
CHANGED
@@ -121,19 +121,19 @@ module Bumbleworks
|
|
121
121
|
# sending it, so it can be properly stored in workitem fields (and
|
122
122
|
# re-instantiated later).
|
123
123
|
#
|
124
|
-
def launch!(process_definition_name,
|
125
|
-
|
126
|
-
Bumbleworks::Ruote.launch(process_definition_name,
|
124
|
+
def launch!(process_definition_name, *args)
|
125
|
+
extract_entity_from_fields!(args.first || {})
|
126
|
+
Bumbleworks::Ruote.launch(process_definition_name, *args)
|
127
127
|
end
|
128
128
|
|
129
129
|
private
|
130
130
|
|
131
|
-
def
|
131
|
+
def extract_entity_from_fields!(fields)
|
132
132
|
begin
|
133
|
-
if entity =
|
134
|
-
|
135
|
-
|
136
|
-
raise InvalidEntity, "Entity#id must be non-null" unless
|
133
|
+
if entity = fields.delete(:entity)
|
134
|
+
fields[:entity_id] = entity.respond_to?(:identifier) ? entity.identifier : entity.id
|
135
|
+
fields[:entity_type] = entity.class.name
|
136
|
+
raise InvalidEntity, "Entity#id must be non-null" unless fields[:entity_id]
|
137
137
|
end
|
138
138
|
rescue NoMethodError => e
|
139
139
|
raise InvalidEntity, "Entity must respond to #id and #class.name"
|
data/lib/bumbleworks/ruote.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "ruote"
|
2
2
|
|
3
|
+
Dir[File.join(File.dirname(__FILE__), 'ruote', 'exp', '*.rb')].each { |f| require f }
|
4
|
+
|
3
5
|
module Bumbleworks
|
4
6
|
class Ruote
|
5
7
|
class CancelTimeout < StandardError; end
|
@@ -41,6 +43,7 @@ module Bumbleworks
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def launch(name, *args)
|
46
|
+
set_catchall_if_needed
|
44
47
|
dashboard.launch(dashboard.variables[name], *args)
|
45
48
|
end
|
46
49
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ruote/exp/flow_expression'
|
2
|
+
|
3
|
+
module Ruote::Exp
|
4
|
+
class BroadcastEventExpression < FlowExpression
|
5
|
+
names :broadcast_event
|
6
|
+
|
7
|
+
def consider_tag
|
8
|
+
update_tree
|
9
|
+
h.updated_tree[1]['tag'] = attribute_text.to_s
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def apply
|
14
|
+
reply_to_parent(h.applied_workitem)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ruote/exp/flow_expression'
|
2
|
+
require 'ruote/exp/fe_await'
|
3
|
+
|
4
|
+
module Ruote::Exp
|
5
|
+
class WaitForEventExpression < AwaitExpression
|
6
|
+
names :wait_for_event
|
7
|
+
|
8
|
+
def apply
|
9
|
+
update_tree
|
10
|
+
h.updated_tree[1]['global'] = true
|
11
|
+
h.updated_tree[1]['left_tag'] = attribute_text.to_s
|
12
|
+
h.updated_tree[1]['merge'] = 'drop'
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def reply(workitem)
|
17
|
+
update_tree
|
18
|
+
if translated_where = attribute(:where, nil, :escape => true)
|
19
|
+
if translated_where.to_s == 'entities_match'
|
20
|
+
translated_where = '${f:entity_id} == ${f:receiver.entity_id} && ${f:entity_type} == ${f:receiver.entity_type}'
|
21
|
+
else
|
22
|
+
translated_where.gsub!('${event:', '${f:')
|
23
|
+
translated_where.gsub!('${this:', '${f:receiver.')
|
24
|
+
end
|
25
|
+
h.updated_tree[1]['where'] = translated_where
|
26
|
+
end
|
27
|
+
workitem['fields']['receiver'] = h.applied_workitem['fields']
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/bumbleworks/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
describe Ruote::Exp::BroadcastEventExpression do
|
2
|
+
before :each do
|
3
|
+
Bumbleworks.reset!
|
4
|
+
Bumbleworks.storage = {}
|
5
|
+
Bumbleworks.start_worker!
|
6
|
+
Bumbleworks.dashboard.add_service('tracer', @tracer = Tracer.new)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'uses attribute text as tag' do
|
10
|
+
Bumbleworks.define_process 'waiter' do
|
11
|
+
await :left_tag => :the_event, :global => true
|
12
|
+
echo 'amazing'
|
13
|
+
end
|
14
|
+
|
15
|
+
Bumbleworks.define_process 'sender' do
|
16
|
+
broadcast_event :the_event
|
17
|
+
end
|
18
|
+
|
19
|
+
waiter = Bumbleworks.launch!('waiter')
|
20
|
+
sender = Bumbleworks.launch!('sender')
|
21
|
+
Bumbleworks.dashboard.wait_for(waiter)
|
22
|
+
@tracer.should == ['amazing']
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
describe Ruote::Exp::WaitForEventExpression do
|
2
|
+
before :each do
|
3
|
+
Bumbleworks.reset!
|
4
|
+
Bumbleworks.storage = {}
|
5
|
+
Bumbleworks.start_worker!
|
6
|
+
Bumbleworks.dashboard.add_service('tracer', @tracer = Tracer.new)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'waits for event' do
|
10
|
+
Bumbleworks.define_process 'waiter' do
|
11
|
+
concurrence :wait_for => 2 do
|
12
|
+
sequence do
|
13
|
+
wait_for_event :nothing_ever_happens_to_me
|
14
|
+
echo 'nothing'
|
15
|
+
end
|
16
|
+
sequence do
|
17
|
+
wait_for_event :yay_it_happened
|
18
|
+
echo 'yay'
|
19
|
+
end
|
20
|
+
sequence do
|
21
|
+
wait_for_event /^yay/
|
22
|
+
noop
|
23
|
+
echo 'yay2'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Bumbleworks.define_process 'sender' do
|
29
|
+
echo 'get ready', :tag => 'not yet'
|
30
|
+
echo 'oh my gosh almost there'
|
31
|
+
echo 'hello', :tag => 'yay_it_happened'
|
32
|
+
end
|
33
|
+
|
34
|
+
waiter = Bumbleworks.launch!('waiter')
|
35
|
+
sender = Bumbleworks.launch!('sender')
|
36
|
+
Bumbleworks.dashboard.wait_for(waiter)
|
37
|
+
@tracer.should == ['get ready', 'oh my gosh almost there', 'hello', 'yay', 'yay2']
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'checks where clause' do
|
41
|
+
Bumbleworks.define_process 'waiter' do
|
42
|
+
wait_for_event :the_event, :where => '${this:special} == ${event:special}'
|
43
|
+
echo 'specials! ${f:special}'
|
44
|
+
end
|
45
|
+
|
46
|
+
Bumbleworks.define_process 'sender' do
|
47
|
+
noop :tag => 'the_event'
|
48
|
+
end
|
49
|
+
|
50
|
+
waiter1 = Bumbleworks.launch!('waiter', 'special' => 1)
|
51
|
+
waiter2 = Bumbleworks.launch!('waiter', 'special' => 2)
|
52
|
+
waiter3 = Bumbleworks.launch!('waiter', 'special' => 3)
|
53
|
+
sender1 = Bumbleworks.launch!('sender', 'not_special' => 1)
|
54
|
+
sender2 = Bumbleworks.launch!('sender', 'special' => 3)
|
55
|
+
|
56
|
+
Bumbleworks.dashboard.wait_for(waiter3)
|
57
|
+
@tracer.should == ['specials! 3']
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'checks entity match' do
|
61
|
+
Bumbleworks.define_process 'waiter' do
|
62
|
+
wait_for_event :the_event, :where => :entities_match
|
63
|
+
echo 'entities! ${f:entity_type},${f:entity_id}'
|
64
|
+
end
|
65
|
+
|
66
|
+
Bumbleworks.define_process 'sender' do
|
67
|
+
noop :tag => 'the_event'
|
68
|
+
end
|
69
|
+
|
70
|
+
waiter1 = Bumbleworks.launch!('waiter', 'entity_type' => 'Pigeon', 'entity_id' => 1)
|
71
|
+
waiter2 = Bumbleworks.launch!('waiter', 'entity_type' => 'Rhubarb', 'entity_id' => 2)
|
72
|
+
waiter3 = Bumbleworks.launch!('waiter', 'entity_type' => 'Rhubarb', 'entity_id' => 1)
|
73
|
+
sender1 = Bumbleworks.launch!('sender', 'entity_type' => 'Pigeon', 'entity_id' => 2)
|
74
|
+
sender2 = Bumbleworks.launch!('sender', 'entity_type' => 'Rhubarb', 'entity_id' => 1)
|
75
|
+
|
76
|
+
Bumbleworks.dashboard.wait_for(waiter3)
|
77
|
+
@tracer.should == ['entities! Rhubarb,1']
|
78
|
+
end
|
79
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
describe Bumbleworks::Ruote do
|
2
2
|
before :each do
|
3
3
|
Bumbleworks.reset!
|
4
|
+
Bumbleworks.storage = {}
|
4
5
|
end
|
5
6
|
|
6
7
|
describe ".cancel_all_processes!" do
|
7
8
|
before :each do
|
8
|
-
Bumbleworks.storage = {}
|
9
9
|
Bumbleworks::Ruote.register_participants
|
10
10
|
Bumbleworks.start_worker!
|
11
11
|
end
|
@@ -43,7 +43,6 @@ describe Bumbleworks::Ruote do
|
|
43
43
|
|
44
44
|
describe ".kill_all_processes!" do
|
45
45
|
before :each do
|
46
|
-
Bumbleworks.storage = {}
|
47
46
|
Bumbleworks::Ruote.register_participants
|
48
47
|
Bumbleworks.start_worker!
|
49
48
|
end
|
@@ -83,24 +82,20 @@ describe Bumbleworks::Ruote do
|
|
83
82
|
end
|
84
83
|
|
85
84
|
it 'creates a new dashboard' do
|
86
|
-
Bumbleworks.storage = {}
|
87
85
|
described_class.dashboard.should be_an_instance_of(Ruote::Dashboard)
|
88
86
|
end
|
89
87
|
|
90
88
|
it 'does not start a worker by default' do
|
91
|
-
Bumbleworks.storage = {}
|
92
89
|
described_class.dashboard.worker.should be_nil
|
93
90
|
end
|
94
91
|
|
95
92
|
it 'starts a worker if :start_worker option is true' do
|
96
|
-
Bumbleworks.storage = {}
|
97
93
|
described_class.dashboard(:start_worker => true).worker.should_not be_nil
|
98
94
|
end
|
99
95
|
end
|
100
96
|
|
101
97
|
describe '.start_worker!' do
|
102
98
|
it 'adds new worker to dashboard and returns worker' do
|
103
|
-
Bumbleworks.storage = {}
|
104
99
|
described_class.dashboard.worker.should be_nil
|
105
100
|
new_worker = described_class.start_worker!
|
106
101
|
new_worker.should be_an_instance_of(Ruote::Worker)
|
@@ -108,7 +103,6 @@ describe Bumbleworks::Ruote do
|
|
108
103
|
end
|
109
104
|
|
110
105
|
it 'joins current thread if :join option is true' do
|
111
|
-
Bumbleworks.storage = {}
|
112
106
|
::Ruote::Dashboard.stub(:new).and_return(dash_double = double('dash', :worker => nil))
|
113
107
|
dash_double.should_receive(:noisy=).with(false)
|
114
108
|
dash_double.should_receive(:join)
|
@@ -116,7 +110,6 @@ describe Bumbleworks::Ruote do
|
|
116
110
|
end
|
117
111
|
|
118
112
|
it 'returns if :join option not true' do
|
119
|
-
Bumbleworks.storage = {}
|
120
113
|
::Ruote::Dashboard.stub(:new).and_return(dash_double = double('dash', :worker => nil))
|
121
114
|
dash_double.should_receive(:noisy=).with(false)
|
122
115
|
dash_double.should_receive(:join).never
|
@@ -124,7 +117,6 @@ describe Bumbleworks::Ruote do
|
|
124
117
|
end
|
125
118
|
|
126
119
|
it 'sets dashboard to noisy if :verbose option true' do
|
127
|
-
Bumbleworks.storage = {}
|
128
120
|
::Ruote::Dashboard.stub(:new).and_return(dash_double = double('dash', :worker => nil))
|
129
121
|
dash_double.should_receive(:noisy=).with(true)
|
130
122
|
described_class.start_worker!(:verbose => true)
|
@@ -139,7 +131,6 @@ describe Bumbleworks::Ruote do
|
|
139
131
|
catchall 'NewCatchall'
|
140
132
|
}
|
141
133
|
|
142
|
-
Bumbleworks.storage = {}
|
143
134
|
described_class.dashboard.participant_list.should be_empty
|
144
135
|
described_class.register_participants ®istration_block
|
145
136
|
described_class.dashboard.participant_list.should have(4).items
|
@@ -152,7 +143,6 @@ describe Bumbleworks::Ruote do
|
|
152
143
|
catchall
|
153
144
|
}
|
154
145
|
|
155
|
-
Bumbleworks.storage = {}
|
156
146
|
described_class.dashboard.participant_list.should be_empty
|
157
147
|
described_class.register_participants ®istration_block
|
158
148
|
described_class.dashboard.participant_list.should have(2).items
|
@@ -160,7 +150,6 @@ describe Bumbleworks::Ruote do
|
|
160
150
|
end
|
161
151
|
|
162
152
|
it 'adds catchall participant if block is nil' do
|
163
|
-
Bumbleworks.storage = {}
|
164
153
|
described_class.dashboard.participant_list.should be_empty
|
165
154
|
described_class.register_participants &nil
|
166
155
|
described_class.dashboard.participant_list.should have(1).item
|
@@ -170,6 +159,7 @@ describe Bumbleworks::Ruote do
|
|
170
159
|
|
171
160
|
describe '.storage' do
|
172
161
|
it 'raise error when storage is not defined' do
|
162
|
+
Bumbleworks.storage = nil
|
173
163
|
expect { described_class.send(:storage) }.to raise_error Bumbleworks::UndefinedSetting
|
174
164
|
end
|
175
165
|
|
@@ -180,4 +170,22 @@ describe Bumbleworks::Ruote do
|
|
180
170
|
described_class.send(:storage)
|
181
171
|
end
|
182
172
|
end
|
173
|
+
|
174
|
+
describe '.launch' do
|
175
|
+
before :each do
|
176
|
+
@pdef = Bumbleworks.define_process 'foo' do; end
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'tells dashboard to launch process' do
|
180
|
+
described_class.dashboard.should_receive(:launch).with(@pdef.tree, 'variable' => 'neat')
|
181
|
+
described_class.launch('foo', 'variable' => 'neat')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'sets catchall if needed' do
|
185
|
+
described_class.dashboard.participant_list.should be_empty
|
186
|
+
described_class.launch('foo')
|
187
|
+
described_class.dashboard.participant_list.should have(1).item
|
188
|
+
described_class.dashboard.participant_list.first.classname.should == 'Bumbleworks::StorageParticipant'
|
189
|
+
end
|
190
|
+
end
|
183
191
|
end
|
@@ -403,7 +403,7 @@ describe Bumbleworks::Task do
|
|
403
403
|
end
|
404
404
|
|
405
405
|
it 'does not raise an error if attempting to claim by same token' do
|
406
|
-
expect{@task.claim('boss')}.not_to raise_error
|
406
|
+
expect{@task.claim('boss')}.not_to raise_error
|
407
407
|
end
|
408
408
|
|
409
409
|
it 'calls before_claim and after_claim callbacks' do
|
@@ -142,9 +142,14 @@ describe Bumbleworks do
|
|
142
142
|
Bumbleworks.launch!(:amazing_process, :hugs => :love)
|
143
143
|
end
|
144
144
|
|
145
|
+
it 'sends all args along' do
|
146
|
+
Bumbleworks::Ruote.should_receive(:launch).with(:amazing_process, { :hugs => :love }, { :whiny => :yup }, :peahen)
|
147
|
+
Bumbleworks.launch!(:amazing_process, { :hugs => :love }, { :whiny => :yup }, :peahen)
|
148
|
+
end
|
149
|
+
|
145
150
|
it 'expands entity params when entity object provided' do
|
146
|
-
Bumbleworks::Ruote.should_receive(:launch).with(:amazing_process, :entity_id => :wiley_e_coyote, :entity_type => 'LovelyEntity')
|
147
|
-
Bumbleworks.launch!(:amazing_process, :entity => LovelyEntity.new(:wiley_e_coyote))
|
151
|
+
Bumbleworks::Ruote.should_receive(:launch).with(:amazing_process, { :entity_id => :wiley_e_coyote, :entity_type => 'LovelyEntity' }, :et_cetera)
|
152
|
+
Bumbleworks.launch!(:amazing_process, { :entity => LovelyEntity.new(:wiley_e_coyote) }, :et_cetera)
|
148
153
|
end
|
149
154
|
|
150
155
|
it 'uses "identifier" method instead of id, if entity has one' do
|
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.30
|
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: 2013-
|
15
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: ruote
|
@@ -173,6 +173,8 @@ files:
|
|
173
173
|
- lib/bumbleworks/process_definition.rb
|
174
174
|
- lib/bumbleworks/rake_tasks.rb
|
175
175
|
- lib/bumbleworks/ruote.rb
|
176
|
+
- lib/bumbleworks/ruote/exp/broadcast_event_expression.rb
|
177
|
+
- lib/bumbleworks/ruote/exp/wait_for_event_expression.rb
|
176
178
|
- lib/bumbleworks/simple_logger.rb
|
177
179
|
- lib/bumbleworks/storage_adapter.rb
|
178
180
|
- lib/bumbleworks/storage_participant.rb
|
@@ -205,6 +207,8 @@ files:
|
|
205
207
|
- spec/lib/bumbleworks/local_participant_spec.rb
|
206
208
|
- spec/lib/bumbleworks/participant_registration_spec.rb
|
207
209
|
- spec/lib/bumbleworks/process_definition_spec.rb
|
210
|
+
- spec/lib/bumbleworks/ruote/exp/broadcast_event_expression_spec.rb
|
211
|
+
- spec/lib/bumbleworks/ruote/exp/wait_for_event_expression_spec.rb
|
208
212
|
- spec/lib/bumbleworks/ruote_spec.rb
|
209
213
|
- spec/lib/bumbleworks/simple_logger_spec.rb
|
210
214
|
- spec/lib/bumbleworks/storage_adapter_spec.rb
|
@@ -215,6 +219,7 @@ files:
|
|
215
219
|
- spec/lib/bumbleworks_spec.rb
|
216
220
|
- spec/spec_helper.rb
|
217
221
|
- spec/support/path_helpers.rb
|
222
|
+
- spec/support/tracer.rb
|
218
223
|
homepage: ''
|
219
224
|
licenses:
|
220
225
|
- MIT
|
@@ -262,6 +267,8 @@ test_files:
|
|
262
267
|
- spec/lib/bumbleworks/local_participant_spec.rb
|
263
268
|
- spec/lib/bumbleworks/participant_registration_spec.rb
|
264
269
|
- spec/lib/bumbleworks/process_definition_spec.rb
|
270
|
+
- spec/lib/bumbleworks/ruote/exp/broadcast_event_expression_spec.rb
|
271
|
+
- spec/lib/bumbleworks/ruote/exp/wait_for_event_expression_spec.rb
|
265
272
|
- spec/lib/bumbleworks/ruote_spec.rb
|
266
273
|
- spec/lib/bumbleworks/simple_logger_spec.rb
|
267
274
|
- spec/lib/bumbleworks/storage_adapter_spec.rb
|
@@ -272,4 +279,5 @@ test_files:
|
|
272
279
|
- spec/lib/bumbleworks_spec.rb
|
273
280
|
- spec/spec_helper.rb
|
274
281
|
- spec/support/path_helpers.rb
|
282
|
+
- spec/support/tracer.rb
|
275
283
|
has_rdoc:
|