bumbleworks 0.0.18 → 0.0.19

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 CHANGED
@@ -8,6 +8,7 @@ require "bumbleworks/participant_registration"
8
8
  require "bumbleworks/ruote"
9
9
  require "bumbleworks/hash_storage"
10
10
  require "bumbleworks/simple_logger"
11
+ require "bumbleworks/storage_participant"
11
12
 
12
13
  module Bumbleworks
13
14
  class UnsupportedMode < StandardError; end
@@ -49,8 +49,9 @@ module Bumbleworks
49
49
 
50
50
  def set_catchall_if_needed
51
51
  last_participant = dashboard.participant_list.last
52
- unless last_participant && last_participant.regex == "^.+$" && last_participant.classname == "Ruote::StorageParticipant"
53
- catchall = ::Ruote::ParticipantEntry.new(["^.+$", ["Ruote::StorageParticipant", {}]])
52
+ unless last_participant && last_participant.regex == "^.+$" &&
53
+ ["Ruote::StorageParticipant", "Bumbleworks::StorageParticipant"].include?(last_participant.classname)
54
+ catchall = ::Ruote::ParticipantEntry.new(["^.+$", ["Bumbleworks::StorageParticipant", {}]])
54
55
  dashboard.participant_list = dashboard.participant_list.push(catchall)
55
56
  end
56
57
  end
@@ -0,0 +1,9 @@
1
+ module Bumbleworks
2
+ class StorageParticipant < ::Ruote::StorageParticipant
3
+ def on_workitem
4
+ return_value = super
5
+ Bumbleworks::Task.new(self[workitem.sid]).on_dispatch
6
+ return return_value
7
+ end
8
+ end
9
+ end
@@ -5,6 +5,7 @@ module Bumbleworks
5
5
  class AlreadyClaimed < StandardError; end
6
6
  class MissingWorkitem < StandardError; end
7
7
  class EntityNotFound < StandardError; end
8
+ class NotCompletable < StandardError; end
8
9
 
9
10
  extend Forwardable
10
11
  delegate [:sid, :fei, :fields, :params, :participant_name, :wfid, :wf_name] => :@workitem
@@ -129,6 +130,7 @@ module Bumbleworks
129
130
 
130
131
  # proceed workitem (saving changes to fields)
131
132
  def complete(metadata = {})
133
+ raise NotCompletable unless completable?
132
134
  before_update(metadata)
133
135
  before_complete(metadata)
134
136
  proceed_workitem
@@ -164,6 +166,11 @@ module Bumbleworks
164
166
  set_claimant(nil)
165
167
  end
166
168
 
169
+ def on_dispatch
170
+ log(:dispatch)
171
+ after_dispatch
172
+ end
173
+
167
174
  def log(action, metadata = {})
168
175
  Bumbleworks.logger.info({
169
176
  :actor => params['claimant'],
@@ -12,6 +12,13 @@ module Bumbleworks
12
12
 
13
13
  def after_complete(params)
14
14
  end
15
+
16
+ def after_dispatch
17
+ end
18
+
19
+ def completable?
20
+ true
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.18"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -2,4 +2,9 @@ module MakeSomeHoneyTask
2
2
  def before_update(params)
3
3
  fields['what_happened'] = params['happening']
4
4
  end
5
+
6
+ def after_dispatch
7
+ fields['i_was_dispatched'] = 'yes_i_was'
8
+ update
9
+ end
5
10
  end
@@ -11,7 +11,7 @@ describe 'Bumbleworks Sample Application' do
11
11
  describe 'initializer' do
12
12
  it 'registers participants' do
13
13
  Bumbleworks.dashboard.participant_list.should have(3).items
14
- Bumbleworks.dashboard.participant_list.map(&:classname).should =~ ['HoneyParticipant', 'MolassesParticipant', 'Ruote::StorageParticipant']
14
+ Bumbleworks.dashboard.participant_list.map(&:classname).should =~ ['HoneyParticipant', 'MolassesParticipant', 'Bumbleworks::StorageParticipant']
15
15
  end
16
16
 
17
17
  it 'loads process definitions' do
@@ -53,5 +53,14 @@ describe 'Bumbleworks Sample Application' do
53
53
  task['what_happened'].should == 'update'
54
54
  end
55
55
  end
56
+
57
+ describe 'dispatching a task' do
58
+ it 'triggers after_dispatch callback' do
59
+ Bumbleworks.launch!('make_honey')
60
+ Bumbleworks.dashboard.wait_for(:dave)
61
+ task = Bumbleworks::Task.for_role('dave').first
62
+ task['i_was_dispatched'].should == 'yes_i_was'
63
+ end
64
+ end
56
65
  end
57
66
 
@@ -70,7 +70,7 @@ describe Bumbleworks::Ruote do
70
70
  described_class.dashboard.participant_list.should be_empty
71
71
  described_class.register_participants &registration_block
72
72
  described_class.dashboard.participant_list.should have(4).items
73
- described_class.dashboard.participant_list.map(&:classname).should =~ ['BeesHoney', 'MapleSyrup', 'NewCatchall', 'Ruote::StorageParticipant']
73
+ described_class.dashboard.participant_list.map(&:classname).should =~ ['BeesHoney', 'MapleSyrup', 'NewCatchall', 'Bumbleworks::StorageParticipant']
74
74
  end
75
75
 
76
76
  it 'does not add storage participant catchall if already exists' do
@@ -91,7 +91,7 @@ describe Bumbleworks::Ruote do
91
91
  described_class.dashboard.participant_list.should be_empty
92
92
  described_class.register_participants &nil
93
93
  described_class.dashboard.participant_list.should have(1).item
94
- described_class.dashboard.participant_list.first.classname.should == 'Ruote::StorageParticipant'
94
+ described_class.dashboard.participant_list.first.classname.should == 'Bumbleworks::StorageParticipant'
95
95
  end
96
96
  end
97
97
 
@@ -19,6 +19,12 @@ describe Bumbleworks::Task do
19
19
  end
20
20
  end
21
21
 
22
+ describe '#completable?' do
23
+ it 'defaults to true on base task' do
24
+ described_class.new(workflow_item).should be_completable
25
+ end
26
+ end
27
+
22
28
  describe '.new' do
23
29
  it 'raises an error if workitem is nil' do
24
30
  expect {
@@ -44,6 +50,39 @@ describe Bumbleworks::Task do
44
50
  end
45
51
  end
46
52
 
53
+ describe '#on_dispatch' do
54
+ before :each do
55
+ Bumbleworks.define_process 'planting_a_noodle' do
56
+ concurrence do
57
+ horse_feeder :task => 'give_the_horse_a_bon_bon'
58
+ end
59
+ end
60
+ end
61
+
62
+ it 'is called when task is dispatched, and triggers callback' do
63
+ described_class.any_instance.should_receive(:on_dispatch)
64
+ Bumbleworks.launch!('planting_a_noodle')
65
+ Bumbleworks.dashboard.wait_for(:horse_feeder)
66
+ end
67
+
68
+ it 'logs dispatch' do
69
+ Bumbleworks.launch!('planting_a_noodle')
70
+ Bumbleworks.dashboard.wait_for(:horse_feeder)
71
+ task = described_class.for_role('horse_feeder').last
72
+ log_entry = Bumbleworks.logger.entries.last[:entry]
73
+ log_entry[:action].should == :dispatch
74
+ log_entry[:target_type].should == 'Task'
75
+ log_entry[:target_id].should == task.id
76
+ end
77
+
78
+ it 'calls after_dispatch callback' do
79
+ task = described_class.new(workflow_item)
80
+ task.stub(:log)
81
+ task.should_receive(:after_dispatch)
82
+ task.on_dispatch
83
+ end
84
+ end
85
+
47
86
  describe '#extend_module' do
48
87
  it 'extends with base module and task module' do
49
88
  task = described_class.new(workflow_item)
@@ -406,6 +445,21 @@ describe Bumbleworks::Task do
406
445
  task.fields['meal'].should == 'root beer and a kite'
407
446
  end
408
447
 
448
+ it 'throws exception if task is not completable' do
449
+ event = Bumbleworks.dashboard.wait_for :dog_mouth
450
+ task = described_class.for_role('dog_mouth').first
451
+ task.stub(:completable?).and_return(false)
452
+ task.should_receive(:before_update).never
453
+ task.should_receive(:before_complete).never
454
+ task.should_receive(:proceed_workitem).never
455
+ task.should_receive(:after_complete).never
456
+ task.should_receive(:after_update).never
457
+ expect {
458
+ task.complete
459
+ }.to raise_error(Bumbleworks::Task::NotCompletable)
460
+ described_class.for_role('dog_mouth').should_not be_empty
461
+ end
462
+
409
463
  it 'calls update and complete callbacks' do
410
464
  task = described_class.new(workflow_item)
411
465
  task.stub(:log)
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.18
4
+ version: 0.0.19
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-07-08 00:00:00.000000000 Z
15
+ date: 2013-07-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ruote
@@ -174,6 +174,7 @@ files:
174
174
  - lib/bumbleworks/ruote.rb
175
175
  - lib/bumbleworks/simple_logger.rb
176
176
  - lib/bumbleworks/storage_adapter.rb
177
+ - lib/bumbleworks/storage_participant.rb
177
178
  - lib/bumbleworks/support.rb
178
179
  - lib/bumbleworks/task.rb
179
180
  - lib/bumbleworks/tasks/base.rb