corn 0.5.4 → 0.5.5

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: 350b0a06c165a783afcb852799e10c9b1e0c7773
4
- data.tar.gz: 35cdfb9da1153beda11dd19f841e7f3b78e498d3
3
+ metadata.gz: 759ed8b4825185d198f5ac578d23004bd8569724
4
+ data.tar.gz: 8a9d9cdf4085189b76c7177c01e05fff8c758b52
5
5
  SHA512:
6
- metadata.gz: 147290199a7b42dd8d2a73b478c5a644e115ba51b0ce03a3211b42278750bc56ff5500741a89662b185710d6eb5c2337d78b3b8b92890be20bacea15b10402e9
7
- data.tar.gz: 7d8450a6461dd85f0d7ddda2ab7a4525f2876ffb3ac8c26f3884b4cb5e51f40249c0ff1c1df5dd83ef74452c2889a2d25b0aae465ddedd08b4ce03f9f1554c24
6
+ metadata.gz: 005c5d90a218768e58b7f392158891961488715067994c7bd470f56380814434f8657b3453a277677dc367dd7f3b0db76006ac0a3876e77c63c99dad22d8cd43
7
+ data.tar.gz: 617f8d391b4fe3f864e1b19ce7c9b5f10f3281b8fd7e7107478dab66ccffb3c617e4cc9f52ebe9622cbaf5f27e292a9c9e3542b3d4bf91c84190111d8ca8f420
@@ -24,11 +24,18 @@ module Corn
24
24
  #
25
25
  config({
26
26
  :logger => Logger.new(STDOUT),
27
- :host => ENV['CORN_HOST'],
28
27
  :client_id => ENV['CORN_CLIENT_ID'],
28
+ :host => ENV['CORN_HOST'],
29
29
  :ssl_verify_peer => false,
30
30
  :ssl_ca_file => nil,
31
- :ssl_ca_path => nil
31
+ :ssl_ca_path => nil,
32
+ # slow request profiler options
33
+ :rack_middleware => Rack::SlowRequestProfiler,
34
+ :rack_slow_request_profiler => Rack::SlowRequestProfiler,
35
+ :slow_request_threshold => 5,
36
+ :profiling => true,
37
+ :sampling_interval => 0.1,
38
+ :post_interval => 2
32
39
  })
33
40
 
34
41
  module_function
@@ -39,8 +46,4 @@ module Corn
39
46
  def submit_url
40
47
  File.join(host, 'profiling_data')
41
48
  end
42
-
43
- def rack_slow_request_profiler
44
- Rack::SlowRequestProfiler
45
- end
46
49
  end
@@ -1,26 +1,18 @@
1
- require 'corn/config'
2
1
  require 'corn/profiler'
3
2
  require 'corn/rack/request_env'
4
3
 
5
4
  module Corn
6
5
  module Rack
7
6
  class SlowRequestProfiler
8
- include Config
9
- config(:profiling => true,
10
- :slow_request_threshold => 5,
11
- :sampling_interval => 0.1,
12
- :post_interval => 2)
13
-
14
7
  class ProfilingApp
15
- def initialize(app, config)
16
- @@prof ||= Profiler.new(config.post_interval,
17
- config.sampling_interval)
8
+ def initialize(app)
9
+ @@prof ||= Profiler.new(Corn.post_interval,
10
+ Corn.sampling_interval)
18
11
  @app = app
19
- @config = config
20
12
  end
21
13
 
22
14
  def call(env)
23
- if @config.profiling?
15
+ if Corn.profiling?
24
16
  @@prof.profile(output_handler(env)) { @app.call(env) }
25
17
  else
26
18
  @app.call(env)
@@ -35,7 +27,7 @@ module Corn
35
27
  def output_handler(env)
36
28
  request_env = RequestEnv.new(env)
37
29
  lambda do |data|
38
- if request_env.time > @config.slow_request_threshold
30
+ if request_env.time > Corn.slow_request_threshold
39
31
  request_env.to_report.merge("data" => data)
40
32
  end
41
33
  end
@@ -43,7 +35,7 @@ module Corn
43
35
  end
44
36
 
45
37
  def initialize(app)
46
- @app = Corn.configured? ? ProfilingApp.new(app, self.class) : app
38
+ @app = Corn.configured? ? ProfilingApp.new(app) : app
47
39
  end
48
40
 
49
41
  def call(env)
@@ -0,0 +1,22 @@
1
+ require 'rails/generators'
2
+
3
+ module Corn
4
+ module Generators
5
+ class ConfigGenerator < Rails::Generators::Base
6
+ def do_config
7
+ create_file "config/initializers/corn_config.rb", <<-RUBY
8
+ Corn.config({
9
+ :logger => Rails.logger,
10
+ # :client_id => ENV["CORN_CLIENT_ID"],
11
+ # :slow_request_threshold => 5,
12
+ # :sampling_interval => 0.1,
13
+ # :post_interval => 2,
14
+ # :profiling => true,
15
+ })
16
+
17
+ Rails.configuration.middleware.use(Corn.rack_middleware)
18
+ RUBY
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: corn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sampling_prof
@@ -40,6 +40,7 @@ files:
40
40
  - lib/corn/rack.rb
41
41
  - lib/corn/rack/request_env.rb
42
42
  - lib/corn/rack/slow_request_profiler.rb
43
+ - lib/generators/corn/config/config_generator.rb
43
44
  homepage: https://github.com/xli/corn
44
45
  licenses:
45
46
  - MIT