drone 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/simple.rb +3 -2
- data/lib/drone/monitoring.rb +8 -8
- data/lib/drone/schedulers/eventmachine.rb +9 -0
- data/lib/drone/utils/exponentially_decaying_sample.rb +1 -1
- data/lib/drone/version.rb +1 -1
- data/specs/common.rb +2 -2
- data/specs/schedulers/eventmachine_spec.rb +76 -0
- data/specs/unit/exponentially_decaying_sample_spec.rb +1 -1
- metadata +5 -5
data/examples/simple.rb
CHANGED
@@ -14,12 +14,13 @@ class User
|
|
14
14
|
@name = name
|
15
15
|
end
|
16
16
|
|
17
|
-
monitor_rate("users:rename")
|
17
|
+
monitor_rate("users:rename:rate")
|
18
18
|
def rename(new_name)
|
19
19
|
@name = new_name
|
20
20
|
end
|
21
21
|
|
22
|
-
monitor_time("users:do_something")
|
22
|
+
monitor_time("users:do_something:time")
|
23
|
+
monitor_rate("users:do_something:rate")
|
23
24
|
def do_something
|
24
25
|
# just eat some cpu
|
25
26
|
0.upto(rand(2000)) do |n|
|
data/lib/drone/monitoring.rb
CHANGED
@@ -75,13 +75,13 @@ module Drone
|
|
75
75
|
rate = @_rate_waiting
|
76
76
|
@_rate_waiting = nil
|
77
77
|
|
78
|
-
define_method("
|
78
|
+
define_method("#{m}_with_meter") do |*args, &block|
|
79
79
|
rate.mark()
|
80
|
-
send("
|
80
|
+
send("#{m}_without_meter", *args, &block)
|
81
81
|
end
|
82
82
|
|
83
|
-
alias_method "
|
84
|
-
alias_method m, "
|
83
|
+
alias_method "#{m}_without_meter", m
|
84
|
+
alias_method m, "#{m}_with_meter"
|
85
85
|
end
|
86
86
|
|
87
87
|
##
|
@@ -91,14 +91,14 @@ module Drone
|
|
91
91
|
timer = @_timer_waiting
|
92
92
|
@_timer_waiting = nil
|
93
93
|
|
94
|
-
define_method("
|
94
|
+
define_method("#{m}_with_timer") do |*args, &block|
|
95
95
|
timer.time do
|
96
|
-
send("
|
96
|
+
send("#{m}_without_timer", *args, &block)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
alias_method "
|
101
|
-
alias_method m, "
|
100
|
+
alias_method "#{m}_without_timer", m
|
101
|
+
alias_method m, "#{m}_with_timer"
|
102
102
|
end
|
103
103
|
|
104
104
|
end
|
data/lib/drone/version.rb
CHANGED
data/specs/common.rb
CHANGED
@@ -4,8 +4,6 @@ require 'rubygems'
|
|
4
4
|
|
5
5
|
puts "Testing with ruby #{RUBY_VERSION} and rubygems #{Gem::VERSION}"
|
6
6
|
|
7
|
-
require 'bundler/setup'
|
8
|
-
|
9
7
|
if (RUBY_VERSION >= "1.9") && ENV['COVERAGE']
|
10
8
|
require 'simplecov'
|
11
9
|
ROOT = File.expand_path('../../', __FILE__)
|
@@ -20,6 +18,8 @@ if (RUBY_VERSION >= "1.9") && ENV['COVERAGE']
|
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
21
|
+
require 'bundler/setup'
|
22
|
+
|
23
23
|
require 'bacon'
|
24
24
|
require 'mocha'
|
25
25
|
require 'delorean'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path('../../common', __FILE__)
|
2
|
+
|
3
|
+
require 'drone/schedulers/eventmachine'
|
4
|
+
|
5
|
+
describe 'Eventmachine Scheduler' do
|
6
|
+
|
7
|
+
describe 'in waiting state' do
|
8
|
+
before do
|
9
|
+
@scheduler = Drone::Schedulers::EMScheduler
|
10
|
+
class << @scheduler
|
11
|
+
def timers_periodic; @timers_periodic; end
|
12
|
+
def timers_once; @timers_once; end
|
13
|
+
end
|
14
|
+
|
15
|
+
EM::reactor_running?.should == false
|
16
|
+
|
17
|
+
@scheduler.reset()
|
18
|
+
end
|
19
|
+
|
20
|
+
should "enqueue timers" do
|
21
|
+
n = 0
|
22
|
+
@scheduler.schedule_once(1){ n = 10 }
|
23
|
+
n.should == 0
|
24
|
+
@scheduler.timers_once.size.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
should "enqueue periodic timers" do
|
28
|
+
n = 0
|
29
|
+
@scheduler.schedule_periodic(1){ n = 10 }
|
30
|
+
n.should == 0
|
31
|
+
@scheduler.timers_periodic.size.should == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
should "start timers when started" do
|
35
|
+
EM::expects(:add_periodic_timer).once.with(12)
|
36
|
+
@scheduler.schedule_periodic(12){ }
|
37
|
+
|
38
|
+
EM.expects(:add_timer).once.with(1)
|
39
|
+
@scheduler.schedule_once(1){ }
|
40
|
+
|
41
|
+
@scheduler.timers_periodic.size.should == 1
|
42
|
+
@scheduler.timers_once.size.should == 1
|
43
|
+
|
44
|
+
@scheduler.start
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
EM.describe 'in started state' do
|
51
|
+
before do
|
52
|
+
@scheduler = Drone::Schedulers::EMScheduler
|
53
|
+
@scheduler.reset()
|
54
|
+
EM::reactor_running?.should == true
|
55
|
+
@scheduler.start()
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'start a timer when a job is scheduled' do
|
59
|
+
EM::expects(:add_timer).with(23)
|
60
|
+
@scheduler.schedule_once(23){}
|
61
|
+
done
|
62
|
+
end
|
63
|
+
|
64
|
+
should 'start run the job and start a periodic timer when a periodic job is scheduled' do
|
65
|
+
n = 0
|
66
|
+
proc = lambda do
|
67
|
+
n+= 1
|
68
|
+
done if n == 2
|
69
|
+
end
|
70
|
+
|
71
|
+
@scheduler.schedule_periodic(0.001, &proc)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: drone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Julien Ammous
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-04-22 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: eventmachine
|
@@ -118,12 +117,12 @@ files:
|
|
118
117
|
- specs/metrics/gauge_spec.rb
|
119
118
|
- specs/metrics/meter_spec.rb
|
120
119
|
- specs/metrics/timer_spec.rb
|
120
|
+
- specs/schedulers/eventmachine_spec.rb
|
121
121
|
- specs/unit/ewma_spec.rb
|
122
122
|
- specs/unit/exponentially_decaying_sample_spec.rb
|
123
123
|
- specs/unit/histogram_spec.rb
|
124
124
|
- specs/unit/monitoring_spec.rb
|
125
125
|
- specs/unit/uniform_sample_spec.rb
|
126
|
-
has_rdoc: true
|
127
126
|
homepage: ""
|
128
127
|
licenses: []
|
129
128
|
|
@@ -147,9 +146,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
146
|
requirements: []
|
148
147
|
|
149
148
|
rubyforge_project: drone
|
150
|
-
rubygems_version: 1.
|
149
|
+
rubygems_version: 1.7.2
|
151
150
|
signing_key:
|
152
151
|
specification_version: 3
|
153
152
|
summary: Drone is a monitoring library
|
154
153
|
test_files: []
|
155
154
|
|
155
|
+
has_rdoc:
|