bumbleworks 0.0.12 → 0.0.13
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/configuration.rb +14 -0
- data/lib/bumbleworks/simple_logger.rb +23 -0
- data/lib/bumbleworks/task.rb +15 -1
- data/lib/bumbleworks/version.rb +1 -1
- data/spec/lib/bumbleworks/configuration_spec.rb +11 -0
- data/spec/lib/bumbleworks/simple_logger_spec.rb +51 -0
- data/spec/lib/bumbleworks/task_spec.rb +64 -19
- data/spec/lib/bumbleworks_spec.rb +7 -0
- metadata +5 -2
data/lib/bumbleworks.rb
CHANGED
@@ -73,6 +73,16 @@ module Bumbleworks
|
|
73
73
|
#
|
74
74
|
define_setting :storage
|
75
75
|
|
76
|
+
# Bumbleworks will attempt to log a variety of events (tasks becoming
|
77
|
+
# available, being claimed/released/completed, etc), and to do so it uses
|
78
|
+
# the logger registered in configuration. If no logger has been registered,
|
79
|
+
# Bumbleworks will use its SimpleLogger, which just adds the entries to an
|
80
|
+
# array. See the SimpleLogger for hints on implementing your own logger;
|
81
|
+
# notably, you can also use an instance Ruby's built-in Logger class.
|
82
|
+
#
|
83
|
+
# default: Bumbleworks::SimpleLogger
|
84
|
+
define_setting :logger
|
85
|
+
|
76
86
|
def initialize
|
77
87
|
@storage_adapters = []
|
78
88
|
end
|
@@ -134,6 +144,10 @@ module Bumbleworks
|
|
134
144
|
@storage_adapters
|
135
145
|
end
|
136
146
|
|
147
|
+
def logger
|
148
|
+
@logger ||= Bumbleworks::SimpleLogger
|
149
|
+
end
|
150
|
+
|
137
151
|
# Clears all memoize variables and configuration settings
|
138
152
|
#
|
139
153
|
def clear!
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bumbleworks
|
2
|
+
class SimpleLogger
|
3
|
+
class << self
|
4
|
+
def entries
|
5
|
+
@entries ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(level, entry)
|
9
|
+
entries << { :level => level, :entry => entry }
|
10
|
+
end
|
11
|
+
|
12
|
+
def clear!
|
13
|
+
@entries = []
|
14
|
+
end
|
15
|
+
|
16
|
+
[:debug, :info, :warn, :error, :fatal].each do |level|
|
17
|
+
define_method level.to_sym do |entry|
|
18
|
+
add level, entry
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/bumbleworks/task.rb
CHANGED
@@ -113,6 +113,7 @@ module Bumbleworks
|
|
113
113
|
def update(metadata = {})
|
114
114
|
before_update(metadata)
|
115
115
|
update_workitem
|
116
|
+
log(:update, metadata)
|
116
117
|
after_update(metadata)
|
117
118
|
end
|
118
119
|
|
@@ -121,6 +122,7 @@ module Bumbleworks
|
|
121
122
|
before_update(metadata)
|
122
123
|
before_complete(metadata)
|
123
124
|
proceed_workitem
|
125
|
+
log(:complete, metadata)
|
124
126
|
after_complete(metadata)
|
125
127
|
after_update(metadata)
|
126
128
|
end
|
@@ -133,6 +135,7 @@ module Bumbleworks
|
|
133
135
|
# Claim task and assign token to claimant
|
134
136
|
def claim(token)
|
135
137
|
set_claimant(token)
|
138
|
+
log(:claim)
|
136
139
|
end
|
137
140
|
|
138
141
|
# true if task is claimed
|
@@ -142,9 +145,20 @@ module Bumbleworks
|
|
142
145
|
|
143
146
|
# release claim on task.
|
144
147
|
def release
|
148
|
+
log(:release)
|
145
149
|
set_claimant(nil)
|
146
150
|
end
|
147
151
|
|
152
|
+
def log(action, metadata = {})
|
153
|
+
Bumbleworks.logger.info({
|
154
|
+
:actor => params['claimant'],
|
155
|
+
:action => action,
|
156
|
+
:object_type => 'Task',
|
157
|
+
:object_id => id,
|
158
|
+
:metadata => metadata.merge(fields)
|
159
|
+
})
|
160
|
+
end
|
161
|
+
|
148
162
|
private
|
149
163
|
|
150
164
|
def storage_participant
|
@@ -165,7 +179,7 @@ module Bumbleworks
|
|
165
179
|
end
|
166
180
|
|
167
181
|
params['claimant'] = token
|
168
|
-
|
182
|
+
update_workitem
|
169
183
|
end
|
170
184
|
end
|
171
185
|
end
|
data/lib/bumbleworks/version.rb
CHANGED
@@ -129,6 +129,17 @@ describe Bumbleworks::Configuration do
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
+
describe '#logger' do
|
133
|
+
it 'returns the registered logger' do
|
134
|
+
configuration.logger = :a_logger
|
135
|
+
configuration.logger.should == :a_logger
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'returns the default simple logger if no logger registered' do
|
139
|
+
configuration.logger.should == Bumbleworks::SimpleLogger
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
132
143
|
describe "#storage" do
|
133
144
|
it 'can set storage directly' do
|
134
145
|
storage = double("Storage")
|
@@ -0,0 +1,51 @@
|
|
1
|
+
describe Bumbleworks::SimpleLogger do
|
2
|
+
before :each do
|
3
|
+
Bumbleworks::SimpleLogger.clear!
|
4
|
+
end
|
5
|
+
|
6
|
+
[:info, :debug, :fatal, :warn, :error].each do |level|
|
7
|
+
describe ".#{level}" do
|
8
|
+
it "adds given object to the log with '#{level}' level" do
|
9
|
+
described_class.should_receive(:add).
|
10
|
+
with(level, :something => :happened)
|
11
|
+
described_class.send(level.to_sym, :something => :happened)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.add' do
|
17
|
+
it 'adds given object to the log at given level' do
|
18
|
+
described_class.add(:info, :super_serious_occurrence)
|
19
|
+
described_class.add(:debug, :weird_thing)
|
20
|
+
described_class.entries.should == [
|
21
|
+
{ :level => :info, :entry => :super_serious_occurrence },
|
22
|
+
{ :level => :debug, :entry => :weird_thing }
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.entries' do
|
28
|
+
it 'returns entries at all levels when given no filter' do
|
29
|
+
described_class.info 'thing'
|
30
|
+
described_class.debug 'other thing'
|
31
|
+
described_class.info 'third thing'
|
32
|
+
described_class.fatal 'final thing'
|
33
|
+
described_class.entries.should == [
|
34
|
+
{ :level => :info, :entry => 'thing' },
|
35
|
+
{ :level => :debug, :entry => 'other thing' },
|
36
|
+
{ :level => :info, :entry => 'third thing' },
|
37
|
+
{ :level => :fatal, :entry => 'final thing' }
|
38
|
+
]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.clear!' do
|
43
|
+
it 'deletes all entries' do
|
44
|
+
described_class.entries.should be_empty
|
45
|
+
described_class.info 'thing'
|
46
|
+
described_class.entries.should_not be_empty
|
47
|
+
described_class.clear!
|
48
|
+
described_class.entries.should be_empty
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -68,11 +68,6 @@ describe Bumbleworks::Task do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
describe '#task_module' do
|
71
|
-
# def task_module
|
72
|
-
# return nil unless nickname
|
73
|
-
# klass_name = Bumbleworks::Support.camelize(nickname)
|
74
|
-
# klass = Bumbleworks::Support.constantize("Bumbleworks::Tasks::#{klass_name}")
|
75
|
-
# end
|
76
71
|
it 'returns nil if no nickname' do
|
77
72
|
task = described_class.new(workflow_item)
|
78
73
|
task.stub(:nickname).and_return(nil)
|
@@ -245,49 +240,65 @@ describe Bumbleworks::Task do
|
|
245
240
|
end
|
246
241
|
|
247
242
|
context 'claiming things' do
|
248
|
-
subject{described_class.new(workflow_item)}
|
249
243
|
before :each do
|
250
|
-
|
251
|
-
|
252
|
-
|
244
|
+
Bumbleworks.define_process 'planting_a_noodle' do
|
245
|
+
noodle_gardener :task => 'plant_noodle_seed'
|
246
|
+
end
|
247
|
+
Bumbleworks.launch!('planting_a_noodle')
|
248
|
+
Bumbleworks.dashboard.wait_for(:noodle_gardener)
|
249
|
+
@task = described_class.for_role('noodle_gardener').first
|
250
|
+
@task.claim('boss')
|
253
251
|
end
|
254
252
|
|
255
253
|
describe '#claim' do
|
256
254
|
it 'sets token on "claimant" param' do
|
257
|
-
|
255
|
+
@task.params['claimant'].should == 'boss'
|
258
256
|
end
|
259
257
|
|
260
258
|
it 'raises an error if already claimed by someone else' do
|
261
|
-
expect{
|
259
|
+
expect{@task.claim('peon')}.to raise_error described_class::AlreadyClaimed
|
262
260
|
end
|
263
261
|
|
264
262
|
it 'does not raise an error if attempting to claim by same token' do
|
265
|
-
expect{
|
263
|
+
expect{@task.claim('boss')}.not_to raise_error described_class::AlreadyClaimed
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'logs event' do
|
267
|
+
log_entry = Bumbleworks.logger.entries.last[:entry]
|
268
|
+
log_entry[:action].should == :claim
|
269
|
+
log_entry[:actor].should == 'boss'
|
266
270
|
end
|
267
271
|
end
|
268
272
|
|
269
273
|
describe '#claimant' do
|
270
274
|
it 'returns token of who has claim' do
|
271
|
-
|
275
|
+
@task.claimant.should == 'boss'
|
272
276
|
end
|
273
277
|
end
|
274
278
|
|
275
279
|
describe '#claimed?' do
|
276
280
|
it 'returns true if claimed' do
|
277
|
-
|
281
|
+
@task.claimed?.should be_true
|
278
282
|
end
|
279
283
|
|
280
284
|
it 'false otherwise' do
|
281
|
-
|
282
|
-
|
285
|
+
@task.params['claimant'] = nil
|
286
|
+
@task.claimed?.should be_false
|
283
287
|
end
|
284
288
|
end
|
285
289
|
|
286
290
|
describe '#release' do
|
287
291
|
it "release claim on workitem" do
|
288
|
-
|
289
|
-
|
290
|
-
|
292
|
+
@task.should be_claimed
|
293
|
+
@task.release
|
294
|
+
@task.should_not be_claimed
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'logs event' do
|
298
|
+
@task.release
|
299
|
+
log_entry = Bumbleworks.logger.entries.last[:entry]
|
300
|
+
log_entry[:action].should == :release
|
301
|
+
log_entry[:actor].should == 'boss'
|
291
302
|
end
|
292
303
|
end
|
293
304
|
end
|
@@ -315,11 +326,28 @@ describe Bumbleworks::Task do
|
|
315
326
|
|
316
327
|
it 'calls before_update and after_update callbacks' do
|
317
328
|
task = described_class.new(workflow_item)
|
329
|
+
task.stub(:log)
|
318
330
|
task.should_receive(:before_update).with(:argue_mints).ordered
|
319
331
|
task.should_receive(:update_workitem).ordered
|
320
332
|
task.should_receive(:after_update).with(:argue_mints).ordered
|
321
333
|
task.update(:argue_mints)
|
322
334
|
end
|
335
|
+
|
336
|
+
it 'logs event' do
|
337
|
+
event = Bumbleworks.dashboard.wait_for :dog_mouth
|
338
|
+
task = described_class.for_role('dog_mouth').first
|
339
|
+
task.params['claimant'] = :some_user
|
340
|
+
task.update(:extra_data => :fancy)
|
341
|
+
Bumbleworks.logger.entries.last.should == {
|
342
|
+
:level => :info, :entry => {
|
343
|
+
:actor => :some_user,
|
344
|
+
:action => :update,
|
345
|
+
:object_type => 'Task',
|
346
|
+
:object_id => task.id,
|
347
|
+
:metadata => { :extra_data => :fancy }.merge(task.fields)
|
348
|
+
}
|
349
|
+
}
|
350
|
+
end
|
323
351
|
end
|
324
352
|
|
325
353
|
describe '#complete' do
|
@@ -338,6 +366,7 @@ describe Bumbleworks::Task do
|
|
338
366
|
|
339
367
|
it 'calls update and complete callbacks' do
|
340
368
|
task = described_class.new(workflow_item)
|
369
|
+
task.stub(:log)
|
341
370
|
task.should_receive(:before_update).with(:argue_mints).ordered
|
342
371
|
task.should_receive(:before_complete).with(:argue_mints).ordered
|
343
372
|
task.should_receive(:proceed_workitem).ordered
|
@@ -345,6 +374,22 @@ describe Bumbleworks::Task do
|
|
345
374
|
task.should_receive(:after_update).with(:argue_mints).ordered
|
346
375
|
task.complete(:argue_mints)
|
347
376
|
end
|
377
|
+
|
378
|
+
it 'logs event' do
|
379
|
+
event = Bumbleworks.dashboard.wait_for :dog_mouth
|
380
|
+
task = described_class.for_role('dog_mouth').first
|
381
|
+
task.params['claimant'] = :some_user
|
382
|
+
task.complete(:extra_data => :fancy)
|
383
|
+
Bumbleworks.logger.entries.last.should == {
|
384
|
+
:level => :info, :entry => {
|
385
|
+
:actor => :some_user,
|
386
|
+
:action => :complete,
|
387
|
+
:object_type => 'Task',
|
388
|
+
:object_id => task.id,
|
389
|
+
:metadata => { :extra_data => :fancy }.merge(task.fields)
|
390
|
+
}
|
391
|
+
}
|
392
|
+
end
|
348
393
|
end
|
349
394
|
|
350
395
|
describe '#has_entity_fields?' do
|
@@ -150,4 +150,11 @@ describe Bumbleworks do
|
|
150
150
|
}.to raise_error(Bumbleworks::InvalidEntity)
|
151
151
|
end
|
152
152
|
end
|
153
|
+
|
154
|
+
describe '.logger' do
|
155
|
+
it 'delegates to configuration.logger' do
|
156
|
+
described_class.configuration.stub(:logger).and_return(:a_logger)
|
157
|
+
described_class.logger.should == :a_logger
|
158
|
+
end
|
159
|
+
end
|
153
160
|
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.13
|
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-06-
|
15
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: ruote
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- lib/bumbleworks/process_definition.rb
|
173
173
|
- lib/bumbleworks/rake_tasks.rb
|
174
174
|
- lib/bumbleworks/ruote.rb
|
175
|
+
- lib/bumbleworks/simple_logger.rb
|
175
176
|
- lib/bumbleworks/storage_adapter.rb
|
176
177
|
- lib/bumbleworks/support.rb
|
177
178
|
- lib/bumbleworks/task.rb
|
@@ -200,6 +201,7 @@ files:
|
|
200
201
|
- spec/lib/bumbleworks/participant_registration_spec.rb
|
201
202
|
- spec/lib/bumbleworks/process_definition_spec.rb
|
202
203
|
- spec/lib/bumbleworks/ruote_spec.rb
|
204
|
+
- spec/lib/bumbleworks/simple_logger_spec.rb
|
203
205
|
- spec/lib/bumbleworks/storage_adapter_spec.rb
|
204
206
|
- spec/lib/bumbleworks/support_spec.rb
|
205
207
|
- spec/lib/bumbleworks/task_spec.rb
|
@@ -254,6 +256,7 @@ test_files:
|
|
254
256
|
- spec/lib/bumbleworks/participant_registration_spec.rb
|
255
257
|
- spec/lib/bumbleworks/process_definition_spec.rb
|
256
258
|
- spec/lib/bumbleworks/ruote_spec.rb
|
259
|
+
- spec/lib/bumbleworks/simple_logger_spec.rb
|
257
260
|
- spec/lib/bumbleworks/storage_adapter_spec.rb
|
258
261
|
- spec/lib/bumbleworks/support_spec.rb
|
259
262
|
- spec/lib/bumbleworks/task_spec.rb
|