nutcracker 0.2.4.2 → 0.2.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # Nutcracker
2
- <a href="https://rubygems.org/gems/graphite-api"><img src=https://fury-badge.herokuapp.com/rb/nutcracker.png></a>
2
+ <a href="https://rubygems.org/gems/nutcracker"><img src=https://fury-badge.herokuapp.com/rb/nutcracker.png></a>
3
3
 
4
- This "library" wraps Twitter's [Nutcracker](https://github.com/twitter/twemproxy) in a gem package and provides ( in the near future I hope ) simple ruby API to the `nutcracker` executable.
5
- For now this repository only contains a Rakefile for building new `nutcracker` gems, look at the last section for more info.
4
+ This library wraps Twitter's [Nutcracker](https://github.com/twitter/twemproxy) in a gem package and provides a simple ruby API to the `nutcracker` executable.
5
+
6
+ ### DISCLAIMER
7
+ this is still a work in progress...
6
8
 
7
9
  ## Motivation
8
10
  The main motivation here is to take the advantages of working with Bundler's dependencies management and to be able to embed Twitter's [Nutcracker](https://github.com/twitter/twemproxy) as a dependency to any Ruby project, this allow you to create small-configuration-only-apps tied to specific version of Nutcracker as I show in the example bellow.
9
11
 
12
+ ## Plugins
13
+ - [nutcracker-graphite](https://github.com/kontera-technologies/nutcracker-graphite) - Send cluster stats to Graphite
14
+ - [nutcracker-ui](https://github.com/kontera-technologies/nutcracker-ui) - Web interface for admin operations and graphs
15
+
10
16
  ### Installation
11
17
  Add this line to your application's Gemfile:
12
18
  ```
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ $:.unshift File.expand_path '../lib', __FILE__
2
2
  require 'nutcracker'
3
3
  require 'rake'
4
4
  require 'rubygems/package_task'
5
+ require "rake/testtask"
5
6
 
6
7
  Nutcracker::GemSpec = eval File.read 'nutcracker.gemspec'
7
8
 
@@ -17,7 +18,7 @@ task :download do
17
18
  File.open("ext/nutcracker/extconf.rb",'w') do |file|
18
19
  file.puts %q{
19
20
  raise "no support for #{RUBY_PLATFORM}" if RUBY_PLATFORM =~ /darwin|mswin|mingw/
20
- system './configure'
21
+ system "./configure --prefix=#{File.expand_path('..',__FILE__)}"
21
22
  system 'make'
22
23
  }
23
24
  end
@@ -39,3 +40,11 @@ task :install => [:gem] do
39
40
  sh "gem install pkg/nutcracker"
40
41
  Rake::Task['clobber_package'].execute
41
42
  end
43
+
44
+ ## Tests stuff
45
+ task :default => :test
46
+
47
+ Rake::TestTask.new(:test) do |t|
48
+ t.libs << "tests"
49
+ t.pattern = "tests/**/*_test.rb"
50
+ end
@@ -1,5 +1,5 @@
1
1
 
2
2
  raise "no support for #{RUBY_PLATFORM}" if RUBY_PLATFORM =~ /darwin|mswin|mingw/
3
- system './configure'
3
+ system "./configure --prefix=#{File.expand_path('..',__FILE__)}"
4
4
  system 'make'
5
5
 
data/lib/nutcracker.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require 'nutcracker/version'
2
2
  require 'socket'
3
3
  require 'json'
4
+ require 'yaml'
4
5
 
5
6
  module Nutcracker
6
7
 
7
8
  def self.start options
8
- Nutcracker::Process.new(options).start
9
+ Nutcracker::Wrapper.new(options).start
9
10
  end
10
11
 
11
12
  def self.executable
@@ -16,17 +17,17 @@ module Nutcracker
16
17
  Nutcracker::VERSION
17
18
  end
18
19
 
19
- class Process
20
- attr_reader :pid, :options
20
+ class Wrapper
21
+ attr_reader :pid, :config_file
21
22
 
22
23
  def initialize options
23
- @options = options
24
+ @config_file = options.fetch :config_file
24
25
  end
25
26
 
26
27
  def start
27
- raise RuntimeError, "Nutcracker is already running (#{pid})..." if running?
28
- @pid = ::Process.spawn("#{Nutcracker.executable} -c #{options.fetch(:config_file).inspect}")
29
- Kernel.at_exit { stop if running? }
28
+ return if running?
29
+ @pid = ::Process.spawn Nutcracker.executable, '-c', config_file
30
+ Kernel.at_exit { kill if running? }
30
31
  self
31
32
  end
32
33
 
@@ -35,31 +36,39 @@ module Nutcracker
35
36
  end
36
37
 
37
38
  def stop
38
- signal :TERM
39
+ sig :TERM
39
40
  end
40
41
 
41
42
  def kill
42
- signal :KILL
43
+ sig :KILL
43
44
  end
44
45
 
45
46
  def join
46
- verify_running! and ::Process.waitpid2 pid
47
+ running! and ::Process.waitpid2 pid
47
48
  end
48
49
 
49
50
  def stats
50
51
  JSON.parse TCPSocket.new('localhost',22222).read rescue {}
51
52
  end
52
53
 
54
+ def config
55
+ @config ||= YAML.load_file config_file
56
+ end
57
+
58
+ # syntactic sugar for initialize plugins
59
+ def use plugin, *args
60
+ Nutcracker.const_get(plugin.to_s.capitalize).start(self,*args)
61
+ end
62
+
53
63
  private
54
64
 
55
- def verify_running!
65
+ def running!
56
66
  running? or raise RuntimeError, "Nutcracker isn't running..."
57
67
  end
58
68
 
59
- def signal term
60
- verify_running! and ::Process.kill(term, pid)
69
+ def sig term
70
+ running! and ::Process.kill(term, pid)
61
71
  end
62
72
 
63
73
  end
64
-
65
74
  end
@@ -1,3 +1,3 @@
1
1
  module Nutcracker
2
- VERSION = "0.2.4.2".freeze
2
+ VERSION = "0.2.4.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutcracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4.2
4
+ version: 0.2.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-22 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 5.0.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mocha
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.14.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.14.0
14
46
  description: Gem/Bundler benefits for Twitter's Nutcraker C app
15
47
  email: eran@kontera.com
16
48
  executables:
@@ -186,6 +218,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
218
  - - ! '>='
187
219
  - !ruby/object:Gem::Version
188
220
  version: '0'
221
+ segments:
222
+ - 0
223
+ hash: -3206659000454237602
189
224
  requirements: []
190
225
  rubyforge_project: ruby-nutcracker
191
226
  rubygems_version: 1.8.25