time_bandits 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2bf8615592babb13d98e031f188af5e32534787
4
- data.tar.gz: fed920d5ae867566c440d4cf47f766b9ae629395
3
+ metadata.gz: 3cf2cfa5710b75af73d4bdcadfe1d85045c54b44
4
+ data.tar.gz: 61361276f09f5d2440169e3380b041a66586c45a
5
5
  SHA512:
6
- metadata.gz: 725590a1323873a12b9d0e165b3fcd9365604c4e89d542be07f74ff24ac29eb5490838de3ba4246b8a11afcb3115880c7d581104cdb8992ce4d361808a6a8516
7
- data.tar.gz: ebfb15dc0488a39a9fd9d4c1f4602347fbdbfe4c0d43a05efa6008226cfe9b2f1b711215a7aed39f9dfcd283348e7364ce2bb2a8dc67077751487b6aa91b3cf8
6
+ metadata.gz: 15ea58bff1730c4dd243706a287a6772483050e51e3d96aef6cac430ea34f59f0a089c57883978217db971ccb38f096eb7451212c3fbc182bead993300bdaa4d
7
+ data.tar.gz: a3c33415c93a4ed090d77bf18581615e6caf4180e2e2ab45112eb695e18f789ca7c004a9e605879474f11755b68a86a11bfcca79483735a49255cd4630cd2f52
data/lib/time_bandits.rb CHANGED
@@ -17,6 +17,7 @@ module TimeBandits
17
17
  autoload :Dalli, 'time_bandits/time_consumers/dalli'
18
18
  autoload :Redis, 'time_bandits/time_consumers/redis'
19
19
  autoload :Sequel, 'time_bandits/time_consumers/sequel'
20
+ autoload :Beetle, 'time_bandits/time_consumers/beetle'
20
21
  end
21
22
 
22
23
  require 'time_bandits/railtie' if defined?(Rails) && Rails::VERSION::STRING >= "3.0"
@@ -0,0 +1,29 @@
1
+ # a time consumer implementation for beetle publishing
2
+ # install into application_controller.rb with the line
3
+ #
4
+ # time_bandit TimeBandits::TimeConsumers::Beetle
5
+ #
6
+
7
+ module TimeBandits
8
+ module TimeConsumers
9
+ class Beetle < BaseConsumer
10
+ prefix :amqp
11
+ fields :time, :calls
12
+ format "Beetle: %.3f(%d)", :time, :calls
13
+
14
+ class Subscriber < ActiveSupport::LogSubscriber
15
+ def publish(event)
16
+
17
+ i = Beetle.instance
18
+ i.time += event.duration
19
+ i.calls += 1
20
+
21
+ return unless logger.debug?
22
+
23
+ debug "%s (%.2fms)" % ["Beetle publish", event.duration]
24
+ end
25
+ end
26
+ Subscriber.attach_to(:beetle)
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -0,0 +1,63 @@
1
+ require_relative '../test_helper'
2
+
3
+ require 'beetle'
4
+
5
+ class BeetleTest < Test::Unit::TestCase
6
+ def setup
7
+ TimeBandits.time_bandits = []
8
+ TimeBandits.add TimeBandits::TimeConsumers::Beetle
9
+ TimeBandits.reset
10
+ @beetle = Beetle::Client.new
11
+ @beetle.configure do
12
+ message :foo
13
+ end
14
+ @bandit = TimeBandits::TimeConsumers::Beetle.instance
15
+ end
16
+
17
+ test "getting metrics" do
18
+ nothing_measured = {
19
+ :amqp_time => 0,
20
+ :amqp_calls => 0
21
+ }
22
+ assert_equal nothing_measured, TimeBandits.metrics
23
+ assert_equal 0, TimeBandits.consumed
24
+ assert_equal 0, TimeBandits.current_runtime
25
+ end
26
+
27
+ test "formatting" do
28
+ @bandit.calls = 3
29
+ assert_equal "Beetle: 0.000(3)", TimeBandits.runtime
30
+ end
31
+
32
+ test "foreground work gets accounted for" do
33
+ work
34
+ check_work
35
+ end
36
+
37
+ test "background work is ignored" do
38
+ Thread.new do
39
+ work
40
+ check_work
41
+ end.join
42
+ m = TimeBandits.metrics
43
+ assert_equal 0, m[:amqp_calls]
44
+ assert_equal 0, m[:amqp_time]
45
+ end
46
+
47
+ private
48
+
49
+ def work
50
+ TimeBandits.reset
51
+ 2.times do
52
+ @beetle.publish("foo")
53
+ @beetle.publish("foo")
54
+ end
55
+ end
56
+
57
+ def check_work
58
+ m = TimeBandits.metrics
59
+ assert_equal 4, m[:amqp_calls]
60
+ assert 0 < m[:amqp_time]
61
+ assert_equal m[:amqp_time], TimeBandits.consumed
62
+ end
63
+ end
data/time_bandits.gemspec CHANGED
@@ -33,5 +33,6 @@ Gem::Specification.new do |s|
33
33
  s.add_development_dependency("redis")
34
34
  s.add_development_dependency("sequel")
35
35
  s.add_development_dependency("activerecord")
36
+ s.add_development_dependency("beetle", ">= 0.4.6")
36
37
  end
37
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_bandits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_variables
@@ -206,6 +206,20 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: beetle
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: 0.4.6
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: 0.4.6
209
223
  description: Rails Completed Line on Steroids
210
224
  email:
211
225
  - skaes@railsexpress.de
@@ -233,6 +247,7 @@ files:
233
247
  - lib/time_bandits/rack/logger40.rb
234
248
  - lib/time_bandits/railtie.rb
235
249
  - lib/time_bandits/time_consumers/base_consumer.rb
250
+ - lib/time_bandits/time_consumers/beetle.rb
236
251
  - lib/time_bandits/time_consumers/dalli.rb
237
252
  - lib/time_bandits/time_consumers/database.rb
238
253
  - lib/time_bandits/time_consumers/garbage_collection.rb
@@ -246,6 +261,7 @@ files:
246
261
  - test/test_helper.rb
247
262
  - test/unit/active_support_notifications_test.rb
248
263
  - test/unit/base_test.rb
264
+ - test/unit/beetle_test.rb
249
265
  - test/unit/dalli_test.rb
250
266
  - test/unit/database_test.rb
251
267
  - test/unit/duplicate_bandits.rb
@@ -282,6 +298,7 @@ test_files:
282
298
  - test/test_helper.rb
283
299
  - test/unit/active_support_notifications_test.rb
284
300
  - test/unit/base_test.rb
301
+ - test/unit/beetle_test.rb
285
302
  - test/unit/dalli_test.rb
286
303
  - test/unit/database_test.rb
287
304
  - test/unit/duplicate_bandits.rb