bumbleworks 0.0.57 → 0.0.58

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,14 @@ module Bumbleworks
4
4
 
5
5
  attr_reader :id
6
6
 
7
+ class << self
8
+ def all
9
+ Bumbleworks.dashboard.process_wfids.map do |wfid|
10
+ new(wfid)
11
+ end
12
+ end
13
+ end
14
+
7
15
  def initialize(wfid)
8
16
  @id = wfid
9
17
  end
@@ -51,7 +51,12 @@ module Bumbleworks
51
51
  options[:method] = :cancel
52
52
  end
53
53
 
54
- dashboard.send(options[:method], wfid)
54
+ if options[:method] == :cancel
55
+ dashboard.cancel(wfid)
56
+ else
57
+ storage.remove_process(wfid)
58
+ end
59
+
55
60
  start_time = Time.now
56
61
  while dashboard.process(wfid)
57
62
  if (Time.now - start_time) > options[:timeout]
@@ -72,25 +77,33 @@ module Bumbleworks
72
77
  options[:method] = :cancel
73
78
  end
74
79
 
75
- notified_processes = []
80
+ notified_process_wfids = []
76
81
 
77
82
  start_time = Time.now
78
- while dashboard.processes.count > 0
79
- new_processes = dashboard.processes - notified_processes
80
- send_cancellation_message(options[:method], new_processes)
81
- notified_processes += new_processes
83
+ while dashboard.process_wfids.count > 0
84
+ new_process_wfids = dashboard.process_wfids - notified_process_wfids
85
+ if options[:method] == :cancel
86
+ send_cancellation_message(options[:method], new_process_wfids)
87
+ else
88
+ storage.clear
89
+ end
90
+ notified_process_wfids += new_process_wfids
82
91
 
83
92
  if (Time.now - start_time) > options[:timeout]
84
93
  error_type = options[:method] == :cancel ? CancelTimeout : KillTimeout
85
- raise error_type, "Process #{options[:method]} taking too long - #{dashboard.processes.count} processes remain. Errors: #{dashboard.errors}"
94
+ raise error_type, "Process #{options[:method]} taking too long - #{dashboard.process_wfids.count} processes remain. Errors: #{dashboard.errors}"
86
95
  end
87
96
  sleep 0.1
88
97
  end
89
98
  end
90
99
 
91
- def send_cancellation_message(method, processes)
92
- processes.each do |ps|
93
- dashboard.send(method, ps.wfid)
100
+ def send_cancellation_message(method, process_wfids)
101
+ process_wfids.each do |wfid|
102
+ if method == :cancel
103
+ dashboard.cancel(wfid)
104
+ else
105
+ storage.remove_process(wfid)
106
+ end
94
107
  end
95
108
  end
96
109
 
@@ -2,6 +2,14 @@ module Bumbleworks
2
2
  class Tracker
3
3
  attr_reader :id, :original_hash
4
4
 
5
+ class << self
6
+ def all
7
+ Bumbleworks.dashboard.get_trackers.map do |tid, attrs|
8
+ new(tid, attrs)
9
+ end
10
+ end
11
+ end
12
+
5
13
  def initialize(id, original_hash = nil)
6
14
  @id = id
7
15
  @original_hash = original_hash || Bumbleworks.dashboard.get_trackers[id]
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.57"
2
+ VERSION = "0.0.58"
3
3
  end
@@ -25,6 +25,16 @@ describe Bumbleworks::Process do
25
25
  end
26
26
  end
27
27
 
28
+ describe '.all' do
29
+ it 'returns instances for all process wfids' do
30
+ bp1 = Bumbleworks.launch!('going_to_the_dance')
31
+ bp2 = Bumbleworks.launch!('going_to_the_dance')
32
+ bp3 = Bumbleworks.launch!('straightening_the_rocks')
33
+ wait_until { Bumbleworks.dashboard.process_wfids.count == 3 }
34
+ described_class.all.should =~ [bp1, bp2, bp3]
35
+ end
36
+ end
37
+
28
38
  describe '.new' do
29
39
  it 'sets workflow id' do
30
40
  bp = described_class.new('apples')
@@ -60,7 +60,6 @@ describe Bumbleworks::Ruote do
60
60
  end
61
61
 
62
62
  it 'times out if process is not killed in time' do
63
- Bumbleworks.dashboard.stub(:kill)
64
63
  Bumbleworks.dashboard.stub(:process).with('woot').and_return(:i_exist)
65
64
  expect {
66
65
  described_class.kill_process!('woot', :timeout => 0.5)
@@ -121,12 +120,12 @@ describe Bumbleworks::Ruote do
121
120
  Bumbleworks.dashboard.wait_for("lazy_guy_#{i}".to_sym)
122
121
  end
123
122
 
124
- Bumbleworks.dashboard.processes.count.should == 5
123
+ Bumbleworks.dashboard.process_wfids.count.should == 5
125
124
 
126
125
  described_class.cancel_all_processes!(:timeout => 30)
127
126
 
128
127
  # 4. When this is all done, all processes should be cancelled.
129
- Bumbleworks.dashboard.processes.count.should == 0
128
+ Bumbleworks.dashboard.process_wfids.count.should == 0
130
129
  end
131
130
 
132
131
  it 'times out if processes are not cancelled in time' do
@@ -140,7 +139,7 @@ describe Bumbleworks::Ruote do
140
139
  end
141
140
  Bumbleworks.launch!('time_hog')
142
141
  Bumbleworks.dashboard.wait_for(:pigheaded)
143
- Bumbleworks.dashboard.processes.count.should == 1
142
+ Bumbleworks.dashboard.process_wfids.count.should == 1
144
143
  expect {
145
144
  described_class.cancel_all_processes!(:timeout => 0.5)
146
145
  }.to raise_error(Bumbleworks::Ruote::CancelTimeout)
@@ -172,15 +171,27 @@ describe Bumbleworks::Ruote do
172
171
  end
173
172
 
174
173
  it 'times out if processes are not killed in time' do
175
- Bumbleworks.dashboard.stub(:kill)
176
- ps1 = double('process', :wfid => nil)
177
- Bumbleworks.dashboard.stub(:processes).and_return([ps1])
174
+ Bumbleworks.dashboard.stub(:process_wfids).and_return(['immortal_wfid'])
178
175
  expect {
179
176
  described_class.kill_all_processes!(:timeout => 0.5)
180
177
  }.to raise_error(Bumbleworks::Ruote::KillTimeout)
181
178
  end
182
179
  end
183
180
 
181
+ describe '.send_cancellation_message' do
182
+ it 'sends cancel message to given wfids if method is cancel' do
183
+ Bumbleworks.dashboard.should_receive(:cancel).with('wfid1')
184
+ Bumbleworks.dashboard.should_receive(:cancel).with('wfid2')
185
+ described_class.send_cancellation_message(:cancel, ['wfid1', 'wfid2'])
186
+ end
187
+
188
+ it 'removes given processes from storage if method is kill' do
189
+ Bumbleworks.dashboard.storage.should_receive(:remove_process).with('wfid1')
190
+ Bumbleworks.dashboard.storage.should_receive(:remove_process).with('wfid2')
191
+ described_class.send_cancellation_message(:kill, ['wfid1', 'wfid2'])
192
+ end
193
+ end
194
+
184
195
  describe '.dashboard' do
185
196
  it 'raises an error if no storage is defined' do
186
197
  Bumbleworks.storage = nil
@@ -7,7 +7,21 @@ describe Bumbleworks::Tracker do
7
7
  Bumbleworks.storage = {}
8
8
  Bumbleworks.dashboard.stub(:get_trackers => fake_trackers)
9
9
  end
10
-
10
+
11
+ describe '.all' do
12
+ it 'returns instances for each tracker in system' do
13
+ trackers = described_class.all
14
+ trackers.all? { |t| t.class == Bumbleworks::Tracker }.should be_true
15
+ trackers.map(&:id).should =~ [
16
+ 'on_error',
17
+ 'global_tracker',
18
+ 'local_tracker',
19
+ 'local_error_intercept',
20
+ 'participant_tracker'
21
+ ]
22
+ end
23
+ end
24
+
11
25
  describe '.new' do
12
26
  it 'sets tracker id and fetches original_hash from dashboard' do
13
27
  tr = described_class.new('global_tracker')
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.57
4
+ version: 0.0.58
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -262,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: 855634540597559898
265
+ hash: 1107263111673014541
266
266
  required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  none: false
268
268
  requirements:
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  version: '0'
272
272
  segments:
273
273
  - 0
274
- hash: 855634540597559898
274
+ hash: 1107263111673014541
275
275
  requirements: []
276
276
  rubyforge_project:
277
277
  rubygems_version: 1.8.23