sponges 0.5.0.3.pre → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6cece34aa41d2f8dad71f3d2135e7abe8aea29c
4
+ data.tar.gz: 9c07a08501a29f2c51c4b46d02ac3216aebfd11e
5
+ SHA512:
6
+ metadata.gz: 163974d2f7704a4c564e6ec237de28daf0ce83ee5e2d25d3f984a3debb2162dc0442dcc66349bcabbc0f7cc227fd951d65d088f2f0d1bf128d5f8fbbff427c7c
7
+ data.tar.gz: a60e3ae1fcffd326f4863db94b4d9005762eea6816736b03ce7250a28bba5fae9c77e174a4965ff27218c520ba943c6d781d5cf7b38719d9c990f49eac1d6750
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # sponges
2
2
 
3
+ [![Code
4
+ Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/AF83/sponges)
5
+ [![Gem
6
+ Version](https://fury-badge.herokuapp.com/rb/sponges.png)](http://badge.fury.io/rb/sponges)
7
+
3
8
  When I build workers, I want them to be like an army of spongebobs, always
4
9
  stressed and eager to work. `sponges` helps you build this army of sponges, to
5
10
  control them, and, well, to kill them gracefully. Making them stressed and eager
@@ -43,12 +48,15 @@ In a file called `example.rb`:
43
48
  require 'sponges'
44
49
 
45
50
  class Worker
46
- def run
51
+ def initialize
47
52
  # Trap the HUP signal, set a boolean to true.
48
53
  trap(:HUP) {
49
54
  Sponges.logger.info "HUP signal trapped, clean stop."
50
55
  @hup = true
51
56
  }
57
+ end
58
+
59
+ def run
52
60
  Sponges.logger.info Process.pid
53
61
  if @hup # is true, we need to shutdown this worker
54
62
  Sponges.logger.info "HUP signal trapped, shutdown..."
@@ -101,7 +109,7 @@ ruby example.rb start -d -s 8 # By default, size equals cpu core's size.
101
109
  Retart gracefully 4 instances of the worker, with a timeout of 3 seconds and
102
110
  daemonize them:
103
111
  ``` bash
104
- ruby example.rb restart -g -d -s 4 -t 3
112
+ ruby example.rb restart -g -s 4 -t 3
105
113
  ```
106
114
 
107
115
  Stop workers with a `QUIT` signal :
@@ -156,6 +164,24 @@ Sponges.configure do |config|
156
164
  end
157
165
  ```
158
166
 
167
+ ## Roadmap
168
+
169
+ ### Version 0.6
170
+
171
+ * Deprecation notice about Redis store removal
172
+
173
+
174
+ ### Version 0.7
175
+
176
+ * Inclusion of Http supervision
177
+
178
+
179
+ ### Version 1.0
180
+
181
+ * Removal of Redis store
182
+
183
+ ## [Changelog](CHANGELOG.md)
184
+
159
185
  ## Acknowledgements
160
186
 
161
187
  sponges would not have been the same without [Jesse
data/lib/sponges/cli.rb CHANGED
@@ -32,7 +32,7 @@ module Sponges
32
32
  Sponges::Commander.new(Sponges::Configuration.worker_name, options).kill
33
33
  end
34
34
 
35
- option :daemonize, type: :boolean
35
+ option :daemonize, type: :boolean, default: true
36
36
  option :size, type: :numeric
37
37
  option :gracefully, type: :boolean
38
38
  option :timeout, type: :numeric
@@ -61,6 +61,7 @@ module Sponges
61
61
  puts "Command not available with the memory store"
62
62
  exit
63
63
  end
64
+ Sponges.logger.warn "Redis's store will be removed in version 1.0!"
64
65
  redis = Nest.new('sponges')
65
66
  puts %q{
66
67
  ___ _ __ ___ _ __ __ _ ___ ___
@@ -33,7 +33,16 @@ module Sponges
33
33
  end
34
34
 
35
35
  def redis
36
- @redis ||= Redis.new
36
+ @redis ||= Redis.new.tap { warn_redis }
37
+ end
38
+
39
+ def redis=(redis)
40
+ warn_redis
41
+ @redis = redis
42
+ end
43
+
44
+ def warn_redis
45
+ Sponges.logger.warn "Redis's store will be removed in version 1.0!"
37
46
  end
38
47
  end
39
48
  end
@@ -2,10 +2,11 @@
2
2
  module Sponges
3
3
  class Handler
4
4
  extend Forwardable
5
- attr_reader :supervisor
5
+ attr_reader :supervisor, :queue, :notifier
6
6
 
7
7
  def initialize(supervisor)
8
8
  @supervisor = supervisor
9
+ @queue, @notifier = IO.pipe
9
10
  at_exit do
10
11
  for_supervisor do
11
12
  Sponges.logger.info "Supervisor exits."
@@ -13,9 +14,17 @@ module Sponges
13
14
  end
14
15
  end
15
16
 
16
- def call(signal)
17
- if Sponges::SIGNALS.include?(signal = find_signal(signal))
18
- send "handler_#{signal.to_s.downcase}", signal
17
+ def push(signal)
18
+ @notifier.puts(signal)
19
+ end
20
+
21
+ def call
22
+ Thread.new do
23
+ while signal = @queue.gets do
24
+ if Sponges::SIGNALS.include?(signal = find_signal(signal.chomp))
25
+ send "handler_#{signal.to_s.downcase}", signal
26
+ end
27
+ end
19
28
  end
20
29
  end
21
30
 
@@ -28,8 +37,8 @@ module Sponges
28
37
  end
29
38
 
30
39
  def find_signal(signal)
31
- return signal if signal.is_a?(Symbol)
32
- if signal = Signal.list.find {|k,v| v == signal }
40
+ return signal.to_sym if signal =~ /\D/
41
+ if signal = Signal.list.find {|k,v| v == signal.to_i }
33
42
  signal.first.to_sym
34
43
  end
35
44
  end
@@ -81,6 +90,7 @@ module Sponges
81
90
 
82
91
  alias handler_quit handler_int
83
92
  alias handler_term handler_int
93
+ alias handler_hup handler_int
84
94
 
85
95
  def kill_them_all(signal)
86
96
  store.children_pids.map do |pid|
@@ -100,7 +110,7 @@ module Sponges
100
110
 
101
111
  def shutdown
102
112
  Process.waitall
103
- Sponges.logger.info "Children shutdown complete.", "Supervisor shutdown. Exiting..."
113
+ Sponges.logger.info "Children shutdown complete. Exiting..."
104
114
  store.clear(name)
105
115
  exit
106
116
  rescue Errno::ESRCH, Errno::ECHILD, SignalException => e
@@ -38,7 +38,6 @@ module Sponges
38
38
  end
39
39
 
40
40
  def kill_supervisor(signal)
41
- Sponges.logger.info "Supervisor receive a #{signal} signal."
42
41
  Process.kill :USR1, @supervisor
43
42
  end
44
43
 
@@ -13,15 +13,18 @@ module Sponges
13
13
  end
14
14
 
15
15
  def start
16
+ handler.call
16
17
  trap_signals
17
18
  options[:size].times do
18
- handler.call :TTIN
19
+ handler.push :TTIN
19
20
  end
20
21
  Sponges.logger.info "Supervisor started, waiting for messages."
21
22
  sleep
23
+ rescue SystemExit => exception
24
+ raise exception
22
25
  rescue Exception => exception
23
26
  Sponges.logger.error exception
24
- handler.call :INT
27
+ handler.push :INT
25
28
  raise exception
26
29
  end
27
30
 
@@ -37,7 +40,7 @@ module Sponges
37
40
 
38
41
  def trap_signals
39
42
  Sponges::SIGNALS.each do |signal|
40
- trap(signal) {|signal| handler.call signal }
43
+ trap(signal) {|signal| handler.push signal }
41
44
  end
42
45
  end
43
46
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Sponges
3
- VERSION = "0.5.0.3.pre"
3
+ VERSION = "0.6.0"
4
4
  end
metadata CHANGED
@@ -1,52 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sponges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.3.pre
5
- prerelease: 8
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - chatgris
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000 Z
11
+ date: 2013-03-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: boson
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: machine
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -84,27 +77,25 @@ files:
84
77
  - lib/sponges/version.rb
85
78
  homepage: http://af83.github.com/sponges
86
79
  licenses: []
80
+ metadata: {}
87
81
  post_install_message:
88
82
  rdoc_options: []
89
83
  require_paths:
90
84
  - lib
91
85
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
86
  requirements:
94
- - - ! '>='
87
+ - - '>='
95
88
  - !ruby/object:Gem::Version
96
89
  version: '0'
97
90
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
91
  requirements:
100
- - - ! '>'
92
+ - - '>='
101
93
  - !ruby/object:Gem::Version
102
- version: 1.3.1
94
+ version: '0'
103
95
  requirements: []
104
96
  rubyforge_project:
105
- rubygems_version: 1.8.24
97
+ rubygems_version: 2.0.0
106
98
  signing_key:
107
- specification_version: 3
99
+ specification_version: 4
108
100
  summary: Turn any ruby object to a daemon controlling an army of sponges.
109
101
  test_files: []
110
- has_rdoc: