bumbleworks 0.0.23 → 0.0.24

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
@@ -25,7 +25,7 @@ module Bumbleworks
25
25
  def_delegators :configuration, setting, "#{setting.to_s}="
26
26
  end
27
27
 
28
- def_delegators Bumbleworks::Ruote, :dashboard, :start_worker!, :cancel_all_processes!
28
+ def_delegators Bumbleworks::Ruote, :dashboard, :start_worker!, :cancel_all_processes!, :kill_all_processes!
29
29
  def_delegator Bumbleworks::ProcessDefinition, :define, :define_process
30
30
 
31
31
  # @public
@@ -3,6 +3,7 @@ require "ruote"
3
3
  module Bumbleworks
4
4
  class Ruote
5
5
  class CancelTimeout < StandardError; end
6
+ class KillTimeout < StandardError; end
6
7
 
7
8
  class << self
8
9
  def dashboard(options = {})
@@ -45,19 +46,28 @@ module Bumbleworks
45
46
 
46
47
  def cancel_all_processes!(options = {})
47
48
  options[:timeout] ||= 5
49
+ unless options[:method] == :kill
50
+ options[:method] = :cancel
51
+ end
52
+
48
53
  dashboard.processes.each do |ps|
49
- dashboard.cancel(ps.wfid)
54
+ dashboard.send(options[:method], ps.wfid)
50
55
  end
51
56
 
52
- cancel_start_time = Time.now
57
+ start_time = Time.now
53
58
  while dashboard.processes.count > 0
54
- if (Time.now - cancel_start_time) > options[:timeout]
55
- raise CancelTimeout, "Cancel taking too long - #{dashboard.processes.count} processes remain"
59
+ if (Time.now - start_time) > options[:timeout]
60
+ error_type = options[:method] == :cancel ? CancelTimeout : KillTimeout
61
+ raise error_type, "Process #{options[:method]} taking too long - #{dashboard.processes.count} processes remain"
56
62
  end
57
63
  sleep 0.1
58
64
  end
59
65
  end
60
66
 
67
+ def kill_all_processes!(options = {})
68
+ cancel_all_processes!(options.merge(:method => :kill))
69
+ end
70
+
61
71
  def register_participants(&block)
62
72
  dashboard.register(&block) if block
63
73
  set_catchall_if_needed
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -41,6 +41,41 @@ describe Bumbleworks::Ruote do
41
41
  end
42
42
  end
43
43
 
44
+ describe ".kill_all_processes!" do
45
+ before :each do
46
+ Bumbleworks.storage = {}
47
+ Bumbleworks::Ruote.register_participants
48
+ Bumbleworks.start_worker!
49
+ end
50
+
51
+ it 'kills all processes without running on_cancel' do
52
+ 5.times do |i|
53
+ Bumbleworks.define_process "do_nothing_#{i}" do
54
+ sequence :on_cancel => 'rethink_life' do
55
+ participant :ref => "lazy_guy_#{i}", :task => 'absolutely_nothing'
56
+ end
57
+ define 'rethink_life' do
58
+ wait '10s'
59
+ end
60
+ end
61
+ Bumbleworks.launch!("do_nothing_#{i}")
62
+ Bumbleworks.dashboard.wait_for("lazy_guy_#{i}".to_sym)
63
+ end
64
+ Bumbleworks.dashboard.processes.count.should == 5
65
+ described_class.kill_all_processes!
66
+ Bumbleworks.dashboard.processes.count.should == 0
67
+ end
68
+
69
+ it 'times out if processes are not killed in time' do
70
+ Bumbleworks.dashboard.stub(:kill)
71
+ ps1 = double('process', :wfid => nil)
72
+ Bumbleworks.dashboard.stub(:processes).and_return([ps1])
73
+ expect {
74
+ described_class.kill_all_processes!(:timeout => 0.5)
75
+ }.to raise_error(Bumbleworks::Ruote::KillTimeout)
76
+ end
77
+ end
78
+
44
79
  describe '.dashboard' do
45
80
  it 'raises an error if no storage is defined' do
46
81
  Bumbleworks.storage = nil
@@ -116,6 +116,11 @@ describe Bumbleworks do
116
116
  Bumbleworks::Ruote.should_receive(:cancel_all_processes!).and_return(:cancelling)
117
117
  Bumbleworks.cancel_all_processes!.should == :cancelling
118
118
  end
119
+
120
+ it 'includes kill_all_processes!' do
121
+ Bumbleworks::Ruote.should_receive(:kill_all_processes!).and_return(:killing)
122
+ Bumbleworks.kill_all_processes!.should == :killing
123
+ end
119
124
  end
120
125
 
121
126
  describe '.launch!' 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.23
4
+ version: 0.0.24
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-12 00:00:00.000000000 Z
15
+ date: 2013-07-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ruote