right_support 2.8.7 → 2.8.8

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.7
1
+ 2.8.8
@@ -121,6 +121,8 @@ module RightSupport::Net
121
121
  :health_check => DEFAULT_HEALTH_CHECK_PROC
122
122
  }
123
123
 
124
+ attr_reader :endpoints
125
+
124
126
  def self.request(endpoints, options={}, &block)
125
127
  new(endpoints, options).request(&block)
126
128
  end
@@ -69,14 +69,13 @@ module RightSupport::Stats
69
69
  # Ignore the update if its type contains "stats"
70
70
  #
71
71
  # @param type [String, Symbol] Type of activity, with anything that is not a symbol, true, or false
72
- # automatically converted to a String and truncated to MAX_TYPE_SIZE characters,
73
- # defaults to nil
72
+ # automatically converted to a String and truncated to MAX_TYPE_SIZE characters; defaults to nil
74
73
  # @param id [String] Unique identifier associated with this activity
75
74
  #
76
75
  # @return [Time] Update time
77
76
  def update(type = nil, id = nil)
78
77
  now = Time.now
79
- if type.nil? || !(type =~ /stats/)
78
+ if type.nil? || type !~ /stats/
80
79
  @interval = average(@interval, now - @last_start_time) if @measure_rate
81
80
  @last_start_time = now
82
81
  @total += 1
@@ -108,6 +107,25 @@ module RightSupport::Stats
108
107
  duration
109
108
  end
110
109
 
110
+ # Update activity and measure its duration
111
+ #
112
+ # @param type [String, Symbol] Type of activity, with anything that is not a symbol, true, or false
113
+ # automatically converted to a String and truncated to MAX_TYPE_SIZE characters; defaults to nil
114
+ # @param id [String] Unique identifier associated with this activity
115
+ #
116
+ # @yield [] required block being measured
117
+ #
118
+ # @return [Object] Result from yield
119
+ #
120
+ # @raise [ArgumentError] block missing
121
+ def measure(type, id)
122
+ raise ArgumentError, "block missing" unless block_given?
123
+ start_time = update(type, id)
124
+ result = yield
125
+ finish(start_time, id)
126
+ result
127
+ end
128
+
111
129
  # Convert average interval to average rate
112
130
  #
113
131
  # @return [Float, NilClass] Recent average rate, or nil if total is 0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "right_support"
8
- s.version = "2.8.7"
8
+ s.version = "2.8.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
12
- s.date = "2013-12-20"
12
+ s.date = "2014-01-09"
13
13
  s.description = "A toolkit of useful, reusable foundation code created by RightScale."
14
14
  s.email = "support@rightscale.com"
15
15
  s.extra_rdoc_files = [
@@ -120,6 +120,11 @@ describe RightSupport::Stats::Activity do
120
120
  @stats.instance_variable_get(:@total).should == 1
121
121
  @stats.instance_variable_get(:@count_per_type).should == {}
122
122
  end
123
+
124
+ it "tracks the id associated with the update" do
125
+ @stats.update("test", "id")
126
+ @stats.instance_variable_get(:@last_id).should == "id"
127
+ end
123
128
  end
124
129
 
125
130
  context :finish do
@@ -146,6 +151,34 @@ describe RightSupport::Stats::Activity do
146
151
  end
147
152
  end
148
153
 
154
+ context :measure do
155
+ it "updates and finishes the activity" do
156
+ flexmock(Time).should_receive(:now).and_return(1000010, 1000020)
157
+ @stats.measure("test", "id") { }
158
+ @stats.instance_variable_get(:@interval).should == 1.0
159
+ @stats.instance_variable_get(:@last_start_time).should == @now + 10
160
+ @stats.instance_variable_get(:@total).should == 1
161
+ @stats.instance_variable_get(:@count_per_type).should == {"test" => 1}
162
+ @stats.instance_variable_get(:@last_id).should == 0
163
+ @stats.instance_variable_get(:@avg_duration).should == 1.0
164
+ end
165
+
166
+ it "yields to the block" do
167
+ called = 0
168
+ flexmock(Time).should_receive(:now).and_return(1000010, 1000030)
169
+ @stats.measure("test", "id") { called += 1}
170
+ called.should == 1
171
+ end
172
+
173
+ it "returns the result of the yield" do
174
+ @stats.measure("test", "id") { 99 }.should == 99
175
+ end
176
+
177
+ it "raises exception if block is missing" do
178
+ lambda { @stats.measure("test", "id") }.should raise_error(ArgumentError, "block missing")
179
+ end
180
+ end
181
+
149
182
  context :avg_rate do
150
183
  it "converts interval to rate" do
151
184
  flexmock(Time).should_receive(:now).and_return(1000020)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
- - 7
10
- version: 2.8.7
9
+ - 8
10
+ version: 2.8.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2013-12-20 00:00:00 Z
23
+ date: 2014-01-09 00:00:00 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  version_requirements: &id001 !ruby/object:Gem::Requirement