bumbleworks 0.0.43 → 0.0.44

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.
@@ -54,6 +54,13 @@ module Bumbleworks
54
54
  end
55
55
  end
56
56
 
57
+ # @public
58
+ # Return true only if store_history (from configuration) is true.
59
+ #
60
+ def store_history?
61
+ configuration.store_history == true
62
+ end
63
+
57
64
  # @public
58
65
  # Yields the global configuration to a block.
59
66
  # @yield [configuration] global configuration
@@ -117,7 +124,6 @@ module Bumbleworks
117
124
  #
118
125
  def reset!
119
126
  @configuration = nil
120
- @participant_block = nil
121
127
  Bumbleworks::Ruote.reset!
122
128
  end
123
129
 
@@ -112,6 +112,18 @@ module Bumbleworks
112
112
  #
113
113
  define_setting :error_handlers
114
114
 
115
+ # If #store_history is true, all messages will be logged in the storage under a special
116
+ # "history" key. These messages will remain in the history even after a process has been
117
+ # cancelled or completed, so the history can be used for auditing.
118
+ #
119
+ # If #store_history is false, history will be stored in-memory, but only the last 1000 messages,
120
+ # and since this is in memory, it's useless for multiple workers in separate processes.
121
+ #
122
+ # Important Note: This setting is *ignored* if the storage is a HashStorage, since having a
123
+ # persistent storage in this case wouldn't make sense (the Hash itself being in-memory).
124
+ #
125
+ define_setting :store_history
126
+
115
127
  def initialize
116
128
  @storage_adapters = []
117
129
  @timeout ||= 5
@@ -141,6 +153,11 @@ module Bumbleworks
141
153
  @tasks_folder ||= default_tasks_directory
142
154
  end
143
155
 
156
+ # Default history storage to true
157
+ def store_history
158
+ @store_history.nil? ? true : @store_history
159
+ end
160
+
144
161
  # Root folder where Bumbleworks looks for ruote assets (participants,
145
162
  # process_definitions, etc.) The root path must be absolute.
146
163
  # It can be defined through a configuration block:
@@ -10,6 +10,10 @@ module Bumbleworks
10
10
  def storage_class
11
11
  Hash
12
12
  end
13
+
14
+ def allow_history_storage?
15
+ false
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -28,6 +28,8 @@ module Bumbleworks
28
28
  # exits.
29
29
  #
30
30
  def start_worker!(options = {})
31
+ set_up_storage_history
32
+ register_error_handler
31
33
  dashboard.noisy = options[:verbose] == true
32
34
  worker = ::Ruote::Worker.new(dashboard.context)
33
35
  if options[:join] == true
@@ -35,7 +37,6 @@ module Bumbleworks
35
37
  else
36
38
  worker.run_in_thread
37
39
  end
38
- register_error_handler
39
40
  worker
40
41
  end
41
42
 
@@ -112,6 +113,12 @@ module Bumbleworks
112
113
  end
113
114
  end
114
115
 
116
+ def set_up_storage_history
117
+ if storage_adapter.allow_history_storage?
118
+ dashboard.add_service('history', 'ruote/log/storage_history', 'Ruote::StorageHistory')
119
+ end
120
+ end
121
+
115
122
  def set_catchall_if_needed
116
123
  last_participant = dashboard.participant_list.last
117
124
  unless last_participant && last_participant.regex == "^.+$" &&
@@ -121,23 +128,28 @@ module Bumbleworks
121
128
  end
122
129
  end
123
130
 
124
- def storage
125
- @storage ||= begin
131
+ def storage_adapter
132
+ @storage_adapter ||= begin
126
133
  all_adapters = Bumbleworks.configuration.storage_adapters
127
- adapter = all_adapters.detect do |adapter|
128
- adapter.use?(Bumbleworks.storage)
134
+ adapter = all_adapters.detect do |potential_adapter|
135
+ potential_adapter.use?(Bumbleworks.storage)
129
136
  end
130
137
  raise UndefinedSetting, "Storage is missing or not supported. Supported: #{all_adapters.map(&:display_name).join(', ')}" unless adapter
131
- adapter.driver.new(Bumbleworks.storage)
138
+ adapter
132
139
  end
133
140
  end
134
141
 
142
+ def storage
143
+ @storage ||= storage_adapter.driver.new(Bumbleworks.storage)
144
+ end
145
+
135
146
  def reset!
136
147
  if @storage
137
148
  @storage.purge!
138
149
  @storage.shutdown
139
150
  end
140
151
  @dashboard.shutdown if @dashboard && @dashboard.respond_to?(:shutdown)
152
+ @storage_adapter = nil
141
153
  @storage = nil
142
154
  @dashboard = nil
143
155
  end
@@ -22,6 +22,10 @@ module Bumbleworks
22
22
  def display_name
23
23
  storage_class.name
24
24
  end
25
+
26
+ def allow_history_storage?
27
+ true
28
+ end
25
29
  end
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.43"
2
+ VERSION = "0.0.44"
3
3
  end
@@ -10,4 +10,5 @@ end
10
10
 
11
11
  Bumbleworks.register_tasks
12
12
  Bumbleworks.load_definitions!
13
+ Bumbleworks.dashboard.add_service('history', 'ruote/log/storage_history', 'Ruote::StorageHistory')
13
14
  Bumbleworks.start_worker!
@@ -266,4 +266,15 @@ describe Bumbleworks::Configuration do
266
266
  configuration.error_handlers.should =~ [Bumbleworks::ErrorLogger, super_handler]
267
267
  end
268
268
  end
269
+
270
+ describe '#store_history' do
271
+ it 'defaults to true' do
272
+ subject.store_history.should be_true
273
+ end
274
+
275
+ it 'can be overridden' do
276
+ subject.store_history = false
277
+ subject.store_history.should be_false
278
+ end
279
+ end
269
280
  end
@@ -0,0 +1,11 @@
1
+ describe Bumbleworks::HashStorage do
2
+ describe '.allow_history_storage?' do
3
+ it 'returns false' do
4
+ described_class.allow_history_storage?.should be_false
5
+ end
6
+
7
+ it 'is a Bumbleworks::StorageAdapter' do
8
+ described_class.is_a? Bumbleworks::StorageAdapter
9
+ end
10
+ end
11
+ end
@@ -226,6 +226,11 @@ describe Bumbleworks::Ruote do
226
226
  described_class.start_worker!
227
227
  end
228
228
 
229
+ it 'calls set_up_storage_history' do
230
+ described_class.should_receive(:set_up_storage_history)
231
+ described_class.start_worker!
232
+ end
233
+
229
234
  it 'does not add another error_handler_participant if already registered' do
230
235
  described_class.register_participants
231
236
  described_class.start_worker!
@@ -235,6 +240,26 @@ describe Bumbleworks::Ruote do
235
240
  end
236
241
  end
237
242
 
243
+ describe '.set_up_storage_history' do
244
+ it 'adds a storage history service to the dashboard if storage adapter allows it' do
245
+ storage_adapter = double('adapter', :allow_history_storage? => true)
246
+ described_class.stub(:storage_adapter => storage_adapter)
247
+ described_class.stub(:storage => Ruote::HashStorage.new({}))
248
+ Bumbleworks.dashboard.should_receive(:add_service).with(
249
+ 'history', 'ruote/log/storage_history', 'Ruote::StorageHistory'
250
+ )
251
+ described_class.set_up_storage_history
252
+ end
253
+
254
+ it 'does not add a storage history service to the dashboard if not allowed' do
255
+ storage_adapter = double('adapter', :allow_history_storage? => false)
256
+ described_class.stub(:storage_adapter => storage_adapter)
257
+ described_class.stub(:storage => Ruote::HashStorage.new({}))
258
+ Bumbleworks.dashboard.should_receive(:add_service).never
259
+ described_class.set_up_storage_history
260
+ end
261
+ end
262
+
238
263
  describe '.register_participants' do
239
264
  it 'loads participants from given block, adding storage participant catchall' do
240
265
  registration_block = Proc.new {
@@ -326,4 +351,49 @@ describe Bumbleworks::Ruote do
326
351
  described_class.dashboard.participant_list.first.classname.should == 'Bumbleworks::StorageParticipant'
327
352
  end
328
353
  end
354
+
355
+ describe '.reset!' do
356
+ it 'clears storage_adapter' do
357
+ described_class.instance_variable_set(:@storage_adapter, 'the adapter')
358
+ described_class.reset!
359
+ described_class.instance_variable_get(:@storage_adapter).should be_nil
360
+ end
361
+
362
+ it 'purges and shuts down storage, then resets storage' do
363
+ old_storage = described_class.storage
364
+ old_storage.should_receive(:purge!)
365
+ old_storage.should_receive(:shutdown)
366
+ described_class.reset!
367
+ described_class.storage.should_not == old_storage
368
+ end
369
+
370
+ it 'skips purging and shutting down of storage if no storage' do
371
+ described_class.instance_variable_set(:@storage, nil)
372
+ expect {
373
+ described_class.reset!
374
+ }.not_to raise_error
375
+ end
376
+
377
+ it 'shuts down dashboard and detaches' do
378
+ old_dashboard = described_class.dashboard
379
+ old_dashboard.should_receive(:shutdown)
380
+ described_class.reset!
381
+ described_class.dashboard.should_not == old_dashboard
382
+ end
383
+
384
+ it 'skips shutting down dashboard if no dashboard' do
385
+ described_class.instance_variable_set(:@dashboard, nil)
386
+ expect {
387
+ described_class.reset!
388
+ }.not_to raise_error
389
+ end
390
+
391
+ it 'skips shutting down dashboard if dashboard can not be shutdown' do
392
+ dashboard = double('dashboard', :respond_to? => false)
393
+ described_class.instance_variable_set(:@dashboard, dashboard)
394
+ dashboard.should_receive(:shutdown).never
395
+ described_class.reset!
396
+ described_class.dashboard.should_not == dashboard
397
+ end
398
+ end
329
399
  end
@@ -35,6 +35,12 @@ describe Bumbleworks::StorageAdapter do
35
35
  end
36
36
  end
37
37
 
38
+ describe '.allow_history_storage?' do
39
+ it 'defaults to true' do
40
+ described_class.allow_history_storage?.should be_true
41
+ end
42
+ end
43
+
38
44
  describe '.use?' do
39
45
  before :each do
40
46
  described_class.stub(:storage_class).and_return(String)
@@ -35,6 +35,15 @@ describe Bumbleworks do
35
35
  end
36
36
  end
37
37
 
38
+ describe '.reset!' do
39
+ it 'resets configuration and resets ruote' do
40
+ old_config = described_class.configuration
41
+ Bumbleworks::Ruote.should_receive(:reset!)
42
+ described_class.reset!
43
+ described_class.configuration.should_not == old_config
44
+ end
45
+ end
46
+
38
47
  describe '.storage' do
39
48
  it 'can set directly' do
40
49
  storage = double("Storage")
@@ -189,4 +198,25 @@ describe Bumbleworks do
189
198
  described_class.logger.should == :a_logger
190
199
  end
191
200
  end
201
+
202
+ describe '.store_history' do
203
+ it 'delegates to configuration.logger' do
204
+ described_class.configuration.stub(:store_history).and_return(:why_not)
205
+ described_class.store_history.should == :why_not
206
+ end
207
+ end
208
+
209
+ describe '#store_history?' do
210
+ it 'returns true if store_history is true' do
211
+ subject.store_history = true
212
+ subject.store_history?.should be_true
213
+ end
214
+
215
+ it 'returns false if store_history is anything but true' do
216
+ subject.store_history = false
217
+ subject.store_history?.should be_false
218
+ subject.store_history = 'penguins'
219
+ subject.store_history?.should be_false
220
+ end
221
+ end
192
222
  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.43
4
+ version: 0.0.44
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-11-21 00:00:00.000000000 Z
15
+ date: 2013-11-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ruote
@@ -211,6 +211,7 @@ files:
211
211
  - spec/lib/bumbleworks/error_handler_participant_spec.rb
212
212
  - spec/lib/bumbleworks/error_handler_spec.rb
213
213
  - spec/lib/bumbleworks/error_logger_spec.rb
214
+ - spec/lib/bumbleworks/hash_storage_spec.rb
214
215
  - spec/lib/bumbleworks/local_participant_spec.rb
215
216
  - spec/lib/bumbleworks/participant_registration_spec.rb
216
217
  - spec/lib/bumbleworks/participant_spec.rb
@@ -244,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
245
  version: '0'
245
246
  segments:
246
247
  - 0
247
- hash: -1294048902539087769
248
+ hash: 1016861213985986002
248
249
  required_rubygems_version: !ruby/object:Gem::Requirement
249
250
  none: false
250
251
  requirements:
@@ -253,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
254
  version: '0'
254
255
  segments:
255
256
  - 0
256
- hash: -1294048902539087769
257
+ hash: 1016861213985986002
257
258
  requirements: []
258
259
  rubyforge_project:
259
260
  rubygems_version: 1.8.23
@@ -282,6 +283,7 @@ test_files:
282
283
  - spec/lib/bumbleworks/error_handler_participant_spec.rb
283
284
  - spec/lib/bumbleworks/error_handler_spec.rb
284
285
  - spec/lib/bumbleworks/error_logger_spec.rb
286
+ - spec/lib/bumbleworks/hash_storage_spec.rb
285
287
  - spec/lib/bumbleworks/local_participant_spec.rb
286
288
  - spec/lib/bumbleworks/participant_registration_spec.rb
287
289
  - spec/lib/bumbleworks/participant_spec.rb