sponges 0.7.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -25
- data/lib/sponges.rb +0 -2
- data/lib/sponges/cli.rb +0 -32
- data/lib/sponges/configuration.rb +3 -22
- data/lib/sponges/runner.rb +3 -4
- data/lib/sponges/store.rb +50 -9
- data/lib/sponges/supervisor.rb +0 -1
- data/lib/sponges/version.rb +1 -1
- metadata +3 -5
- data/lib/sponges/store/memory.rb +0 -64
- data/lib/sponges/store/redis.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bc1020da5a609d654d69a21d51fc0b77d05ea5c
|
4
|
+
data.tar.gz: bf1a641c5e4a66379fd9e0bcf58cf067a951c129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60249ea5adc99e00704121e52eec82ba4edb4f4275467e89f9f0f6cc3bf5c395ade5991b22704f84996e4ef0e5d5eec66285060dfc7dc265c53817fedaf1bf14
|
7
|
+
data.tar.gz: fee8bbcee7199bfde7a19d7d4a068ef083c42c921b8856b75dae539eff44f921a0221685e8d99e49c63f077e54570dfbda575be54cb9709d50f04b148de09d09
|
data/README.md
CHANGED
@@ -71,7 +71,6 @@ end
|
|
71
71
|
|
72
72
|
Sponges.configure do |config|
|
73
73
|
config.logger = MyCustomLogger.new # optionnal
|
74
|
-
config.redis = Redis.new # optionnal
|
75
74
|
config.size = 3 # optionnal, default to cpu's size
|
76
75
|
config.daemonize = true # optionnal, default to false
|
77
76
|
config.port = 5032 # optionnal, default to 5032
|
@@ -200,30 +199,6 @@ example of response:
|
|
200
199
|
}
|
201
200
|
```
|
202
201
|
|
203
|
-
## Stores
|
204
|
-
|
205
|
-
sponges can store pids in memory or in redis. Memory is the default store. The
|
206
|
-
`list` command is not available with the memory store.
|
207
|
-
|
208
|
-
To select the redis store, you need to add `nest` to your application's
|
209
|
-
Gemfile, and do the following.
|
210
|
-
|
211
|
-
``` ruby
|
212
|
-
gem "nest"
|
213
|
-
```
|
214
|
-
|
215
|
-
``` ruby
|
216
|
-
Sponges.configure do |config|
|
217
|
-
config.store = :redis
|
218
|
-
end
|
219
|
-
```
|
220
|
-
|
221
|
-
## Roadmap
|
222
|
-
|
223
|
-
### Version 1.0
|
224
|
-
|
225
|
-
* Removal of Redis store
|
226
|
-
|
227
202
|
## [Changelog](CHANGELOG.md)
|
228
203
|
|
229
204
|
## Acknowledgements
|
data/lib/sponges.rb
CHANGED
@@ -16,8 +16,6 @@ require_relative 'sponges/runner'
|
|
16
16
|
require_relative 'sponges/commander'
|
17
17
|
require_relative 'sponges/cli'
|
18
18
|
require_relative 'sponges/store'
|
19
|
-
require_relative 'sponges/store/memory'
|
20
|
-
require_relative 'sponges/store/redis'
|
21
19
|
|
22
20
|
module Sponges
|
23
21
|
STOP_SIGNALS = [:INT, :QUIT, :TERM]
|
data/lib/sponges/cli.rb
CHANGED
@@ -54,38 +54,6 @@ module Sponges
|
|
54
54
|
Sponges::Commander.new(Sponges::Configuration.worker_name, options).
|
55
55
|
decrement
|
56
56
|
end
|
57
|
-
|
58
|
-
desc "Show running processes"
|
59
|
-
def list
|
60
|
-
if Sponges::Configuration.store == :memory
|
61
|
-
puts "Command not available with the memory store"
|
62
|
-
exit
|
63
|
-
end
|
64
|
-
Sponges.logger.warn "Redis's store will be removed in version 1.0!"
|
65
|
-
redis = Nest.new('sponges')
|
66
|
-
puts %q{
|
67
|
-
___ _ __ ___ _ __ __ _ ___ ___
|
68
|
-
/ __| '_ \ / _ \| '_ \ / _` |/ _ \/ __|
|
69
|
-
\__ \ |_) | (_) | | | | (_| | __/\__ \
|
70
|
-
|___/ .__/ \___/|_| |_|\__, |\___||___/
|
71
|
-
| | __/ |
|
72
|
-
|_| |___/
|
73
|
-
}.gsub(/^\n/, '') + "\n"
|
74
|
-
puts "Workers:"
|
75
|
-
Array(redis[:hostnames].smembers).each do |hostname|
|
76
|
-
puts hostname.rjust(6)
|
77
|
-
Array(redis[hostname][:workers].smembers).each do |worker|
|
78
|
-
puts worker.rjust(6)
|
79
|
-
puts "supervisor".rjust(15)
|
80
|
-
puts redis[hostname][:worker][worker][:supervisor].get.rjust(12)
|
81
|
-
puts "children".rjust(13)
|
82
|
-
Array(redis[hostname][:worker][worker][:pids].smembers).each do |pid|
|
83
|
-
puts pid.rjust(12)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
puts "\n"
|
88
|
-
end
|
89
57
|
end
|
90
58
|
|
91
59
|
end
|
@@ -4,9 +4,8 @@ module Sponges
|
|
4
4
|
#
|
5
5
|
class Configuration
|
6
6
|
class << self
|
7
|
-
ACCESSOR = [:worker_name, :worker, :logger, :
|
8
|
-
|
9
|
-
:port
|
7
|
+
ACCESSOR = [:worker_name, :worker, :logger, :size, :daemonize,
|
8
|
+
:after_fork, :timeout, :gracefully, :store, :port
|
10
9
|
]
|
11
10
|
attr_accessor *ACCESSOR
|
12
11
|
|
@@ -15,9 +14,8 @@ module Sponges
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def configuration
|
18
|
-
ACCESSOR.
|
17
|
+
ACCESSOR.each_with_object({}) do |conf, method|
|
19
18
|
conf[method] = send(method)
|
20
|
-
conf
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -29,27 +27,10 @@ module Sponges
|
|
29
27
|
Hook._on_chld = block
|
30
28
|
end
|
31
29
|
|
32
|
-
def store
|
33
|
-
@store || :memory
|
34
|
-
end
|
35
|
-
|
36
30
|
def port
|
37
31
|
@port || 5032
|
38
32
|
end
|
39
33
|
|
40
|
-
def redis
|
41
|
-
@redis ||= Redis.new.tap { warn_redis }
|
42
|
-
end
|
43
|
-
|
44
|
-
def redis=(redis)
|
45
|
-
warn_redis
|
46
|
-
@redis = redis
|
47
|
-
end
|
48
|
-
|
49
|
-
def warn_redis
|
50
|
-
Sponges.logger.warn "Redis's store will be removed in version 1.0!"
|
51
|
-
end
|
52
|
-
|
53
34
|
end
|
54
35
|
end
|
55
36
|
|
data/lib/sponges/runner.rb
CHANGED
@@ -14,7 +14,6 @@ module Sponges
|
|
14
14
|
Sponges.logger.error "Runner #{@name} already started."
|
15
15
|
exit
|
16
16
|
end
|
17
|
-
store.register_hostname Socket.gethostname
|
18
17
|
end
|
19
18
|
|
20
19
|
def start
|
@@ -33,12 +32,12 @@ module Sponges
|
|
33
32
|
|
34
33
|
def trap_signals
|
35
34
|
Sponges::SIGNALS.each do |signal|
|
36
|
-
trap(signal) {|signal| kill_supervisor
|
35
|
+
trap(signal) {|signal| kill_supervisor }
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
|
-
def kill_supervisor
|
41
|
-
Process.kill
|
39
|
+
def kill_supervisor
|
40
|
+
Process.kill :QUIT, @supervisor
|
42
41
|
end
|
43
42
|
|
44
43
|
def default_options
|
data/lib/sponges/store.rb
CHANGED
@@ -1,15 +1,56 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Sponges
|
3
3
|
class Store
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
attr_writer :supervisor_pid
|
7
|
+
attr_reader :pids, :name
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@pids, @name = [], name
|
11
|
+
end
|
12
|
+
|
13
|
+
def_delegator :@pids, :<<, :add_children
|
14
|
+
def_delegator :@pids, :delete, :delete_children
|
15
|
+
|
16
|
+
def supervisor_pid
|
17
|
+
return @supervisor_pid if @supervisor_pid
|
18
|
+
s = find_supervisor
|
19
|
+
@supervisor_pid = s.pid if s
|
20
|
+
end
|
21
|
+
|
22
|
+
def children_pids
|
23
|
+
@pids.any? ? @pids : find_childs.map(&:pid)
|
24
|
+
end
|
25
|
+
|
26
|
+
def running?
|
27
|
+
!!find_supervisor
|
28
|
+
end
|
29
|
+
|
30
|
+
def register(supervisor_pid)
|
31
|
+
@supervisor_pid = supervisor_pid
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear(name)
|
35
|
+
pids.clear
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def supervisor_name
|
41
|
+
"#{name}_supervisor"
|
42
|
+
end
|
43
|
+
|
44
|
+
def childs_name
|
45
|
+
"#{name}_child"
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_supervisor
|
49
|
+
Sys::ProcTable.ps.select {|f| f.cmdline == supervisor_name }.first
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_childs
|
53
|
+
Sys::ProcTable.ps.select {|f| f.cmdline =~ /^#{childs_name}/ }
|
13
54
|
end
|
14
55
|
end
|
15
56
|
end
|
data/lib/sponges/supervisor.rb
CHANGED
@@ -9,7 +9,6 @@ module Sponges
|
|
9
9
|
def initialize(name, options, store, block)
|
10
10
|
@name, @options, @store, @block = name, options, store, block
|
11
11
|
$PROGRAM_NAME = "#{@name}_supervisor"
|
12
|
-
store.on_fork
|
13
12
|
store.register Process.pid
|
14
13
|
@children_seen = 0
|
15
14
|
@handler = Handler.new self
|
data/lib/sponges/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sponges
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chatgris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: boson
|
@@ -73,8 +73,6 @@ files:
|
|
73
73
|
- lib/sponges/response.rb
|
74
74
|
- lib/sponges/runner.rb
|
75
75
|
- lib/sponges/store.rb
|
76
|
-
- lib/sponges/store/memory.rb
|
77
|
-
- lib/sponges/store/redis.rb
|
78
76
|
- lib/sponges/supervisor.rb
|
79
77
|
- lib/sponges/version.rb
|
80
78
|
homepage: http://af83.github.com/sponges
|
@@ -96,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
94
|
version: '0'
|
97
95
|
requirements: []
|
98
96
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.0.0
|
97
|
+
rubygems_version: 2.0.0
|
100
98
|
signing_key:
|
101
99
|
specification_version: 4
|
102
100
|
summary: Turn any ruby object to a daemon controlling an army of sponges.
|
data/lib/sponges/store/memory.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Sponges
|
3
|
-
class Store
|
4
|
-
class Memory
|
5
|
-
extend Forwardable
|
6
|
-
|
7
|
-
attr_writer :supervisor_pid
|
8
|
-
attr_reader :pids, :name
|
9
|
-
|
10
|
-
def initialize(name)
|
11
|
-
@pids, @name = [], name
|
12
|
-
end
|
13
|
-
|
14
|
-
def_delegator :@pids, :<<, :add_children
|
15
|
-
def_delegator :@pids, :delete, :delete_children
|
16
|
-
|
17
|
-
def supervisor_pid
|
18
|
-
return @supervisor_pid if @supervisor_pid
|
19
|
-
s = find_supervisor
|
20
|
-
@supervisor_pid = s.pid if s
|
21
|
-
end
|
22
|
-
|
23
|
-
def children_pids
|
24
|
-
@pids.any? ? @pids : find_childs.map(&:pid)
|
25
|
-
end
|
26
|
-
|
27
|
-
def running?
|
28
|
-
!!find_supervisor
|
29
|
-
end
|
30
|
-
|
31
|
-
def register(supervisor_pid)
|
32
|
-
@supervisor_pid = supervisor_pid
|
33
|
-
end
|
34
|
-
|
35
|
-
def register_hostname(hostname)
|
36
|
-
end
|
37
|
-
|
38
|
-
def on_fork
|
39
|
-
end
|
40
|
-
|
41
|
-
def clear(name)
|
42
|
-
pids.clear
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def supervisor_name
|
48
|
-
"#{name}_supervisor"
|
49
|
-
end
|
50
|
-
|
51
|
-
def childs_name
|
52
|
-
"#{name}_child"
|
53
|
-
end
|
54
|
-
|
55
|
-
def find_supervisor
|
56
|
-
Sys::ProcTable.ps.select {|f| f.cmdline == supervisor_name }.first
|
57
|
-
end
|
58
|
-
|
59
|
-
def find_childs
|
60
|
-
Sys::ProcTable.ps.select {|f| f.cmdline =~ /^#{childs_name}/ }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/sponges/store/redis.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Sponges
|
3
|
-
class Store
|
4
|
-
class Redis
|
5
|
-
attr_reader :redis, :hostname_store, :name
|
6
|
-
private :redis, :hostname_store
|
7
|
-
|
8
|
-
def initialize(name)
|
9
|
-
@name = name
|
10
|
-
@redis ||= Nest.new('sponges', Configuration.redis)
|
11
|
-
@hostname_store = @redis[Socket.gethostname]
|
12
|
-
end
|
13
|
-
|
14
|
-
def supervisor_pid
|
15
|
-
hostname_store[:worker][name][:supervisor].get
|
16
|
-
end
|
17
|
-
|
18
|
-
def children_pids
|
19
|
-
Array(hostname_store[:worker][name][:pids].smembers)
|
20
|
-
end
|
21
|
-
|
22
|
-
def running?
|
23
|
-
if pid = hostname_store[:worker][name][:supervisor].get
|
24
|
-
begin
|
25
|
-
Process.kill 0, pid.to_i
|
26
|
-
true
|
27
|
-
rescue Errno::ESRCH => e
|
28
|
-
hostname_store[:worker][name][:supervisor].del
|
29
|
-
false
|
30
|
-
end
|
31
|
-
else
|
32
|
-
false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def register_hostname(hostname)
|
37
|
-
redis[:hostnames].sadd hostname
|
38
|
-
end
|
39
|
-
|
40
|
-
def register(supervisor_pid)
|
41
|
-
hostname_store[:workers].sadd name
|
42
|
-
hostname_store[:worker][name][:supervisor].set supervisor_pid
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_children(pid)
|
46
|
-
hostname_store[:worker][name][:pids].sadd pid
|
47
|
-
end
|
48
|
-
|
49
|
-
def delete_children(pid)
|
50
|
-
hostname_store[:worker][name][:pids].srem pid
|
51
|
-
end
|
52
|
-
|
53
|
-
def clear(name)
|
54
|
-
hostname_store[:worker][name][:supervisor].del
|
55
|
-
hostname_store[:workers].srem name
|
56
|
-
hostname_store[:worker][name][:pids].del
|
57
|
-
end
|
58
|
-
|
59
|
-
def on_fork
|
60
|
-
Sponges::Configuration.redis.client.reconnect
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def find_supervisor
|
66
|
-
Sys::ProcTable.ps.select {|f| f.cmdline == supervisor_name }.first
|
67
|
-
end
|
68
|
-
|
69
|
-
def find_childs
|
70
|
-
Sys::ProcTable.ps.select {|f| f.cmdline =~ /^#{childs_name}/ }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|