sponges 1.0.1 → 1.1.0

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: f0cac568a3c8a62e54982cfc0f148a3364ce621d
4
- data.tar.gz: b43a3a61760b50152a5822530f40164cc3a8929d
3
+ metadata.gz: 7b193b36206a51da04f4e60d9415bbf839739b9b
4
+ data.tar.gz: 27a8cc10e491c9fd326d2fee7c6325e12ee78ab3
5
5
  SHA512:
6
- metadata.gz: 03fc14026327a11541b3c6e64e2ace1589ef4082e99db43c3d37058ffc603a6e4639606c3cffc5ea1c8a14694183ccd753e1d6a619a24141884732bde5440dff
7
- data.tar.gz: 21798560537ad2d3cded92ee268586a476eff76dceffd7746b7c74719dee87db4568e14a577205b276edc7aa12d8cccb7e13fefb672da6a48700948cb56ae95e
6
+ metadata.gz: 0f025d421b02df7c29b9a8933ed276befd503e4566708d2247d81404967ebb51600446ab74774dbfc17e343263e87c1271361da588bbdf7760f07519c9ed9bc6
7
+ data.tar.gz: b38c5679db7ba703a0d2a2315997b293b5265e930501c46fdec91fe9deb8a6b2bacf587803115dbf5b4feee44e0df9aae4a30247b08ed51d9686de1128037fcb
data/README.md CHANGED
@@ -76,6 +76,9 @@ Sponges.configure do |config|
76
76
  config.size = 3 # optionnal, default to cpu's size
77
77
  config.daemonize = true # optionnal, default to false
78
78
  config.port = 5032 # optionnal, default to 5032
79
+ # polling on supervisor, this is use to shutdown children in case supervisor
80
+ # receive a `SIGKILL` signal.
81
+ config.polling = 60 # optionnal, default to 60
79
82
  config.after_fork do
80
83
  puts "Execute code when a child process is created"
81
84
  end
data/lib/sponges.rb CHANGED
@@ -7,7 +7,9 @@ require 'forwardable'
7
7
  require 'socket'
8
8
  require 'json'
9
9
  require_relative 'sponges/version'
10
+ require_relative 'sponges/alive'
10
11
  require_relative 'sponges/configuration'
12
+ require_relative 'sponges/worker'
11
13
  require_relative 'sponges/handler'
12
14
  require_relative 'sponges/response'
13
15
  require_relative 'sponges/listener'
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module Sponges
3
+ module Alive
4
+ # Check processus presence by its pid.
5
+ #
6
+ # @param [Integer] pid
7
+ #
8
+ # @return [Boolean]
9
+ #
10
+ def alive?(pid)
11
+ !Sys::ProcTable.ps.find {|f| f.pid == pid }.nil?
12
+ end
13
+ private :alive?
14
+ end
15
+ end
@@ -6,6 +6,7 @@ module Sponges
6
6
  # messages like 'stop' or 'restart'
7
7
  #
8
8
  class Commander
9
+ include Sponges::Alive
9
10
  attr_reader :store
10
11
 
11
12
  def initialize(name, options = {})
@@ -105,10 +106,6 @@ module Sponges
105
106
  end
106
107
  end
107
108
 
108
- def alive?(pid)
109
- !Sys::ProcTable.ps.find {|f| f.pid == pid }.nil?
110
- end
111
-
112
109
  def gracefully?
113
110
  !!@options[:gracefully]
114
111
  end
@@ -5,7 +5,8 @@ module Sponges
5
5
  class Configuration
6
6
  class << self
7
7
  ACCESSOR = [:worker_name, :worker, :logger, :size, :daemonize,
8
- :after_fork, :timeout, :gracefully, :store, :port
8
+ :after_fork, :timeout, :gracefully, :store, :port,
9
+ :polling
9
10
  ]
10
11
  attr_accessor *ACCESSOR
11
12
 
@@ -31,6 +32,10 @@ module Sponges
31
32
  @port || 5032
32
33
  end
33
34
 
35
+ def pooling
36
+ @pooling || 60
37
+ end
38
+
34
39
  end
35
40
  end
36
41
 
@@ -120,12 +120,7 @@ module Sponges
120
120
 
121
121
  def fork_children
122
122
  name = children_name
123
- pid = fork do
124
- $PROGRAM_NAME = name
125
- (Sponges::STOP_SIGNALS + [:HUP]).each{ |sig| trap(sig) { exit!(0) } }
126
- Sponges::Hook.after_fork
127
- supervisor.call
128
- end
123
+ pid = Sponges::Worker.new(supervisor, name).call
129
124
  Sponges.logger.info "Supervisor create a child with #{pid} pid."
130
125
  store.add_children pid
131
126
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Sponges
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ module Sponges
3
+ # This class helps building new workers.
4
+ #
5
+ class Worker
6
+ include Sponges::Alive
7
+ attr_reader :supervisor, :name
8
+
9
+ # Initialize an Worker with a supervisor and its future name
10
+ #
11
+ #
12
+ # @param [Sponges::Supervisor] supervisor
13
+ # @param [String] name
14
+ #
15
+ # @return [undefined]
16
+ #
17
+ def initialize(supervisor, name)
18
+ @supervisor, @name = supervisor, name
19
+ end
20
+
21
+ # Forks a brandly new worker.
22
+ #
23
+ # @return [Integer] Pid of the new worker
24
+ #
25
+ def call
26
+ fork do
27
+ $PROGRAM_NAME = name
28
+ (Sponges::STOP_SIGNALS + [:HUP]).each { |sig| trap(sig) { exit!(0) } }
29
+ trap_supervisor_sigkill!
30
+ Sponges::Hook.after_fork
31
+ supervisor.call
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def trap_supervisor_sigkill!
38
+ Thread.new do
39
+ while alive?(supervisor.pid) do
40
+ Sponges.logger.debug Configuration.polling
41
+ sleep Configuration.polling
42
+ end
43
+ exit
44
+ end
45
+ end
46
+ end
47
+ end
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: 1.0.1
4
+ version: 1.1.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-04-17 00:00:00.000000000 Z
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: boson
@@ -65,6 +65,7 @@ files:
65
65
  - LICENSE
66
66
  - README.md
67
67
  - lib/sponges.rb
68
+ - lib/sponges/alive.rb
68
69
  - lib/sponges/cli.rb
69
70
  - lib/sponges/commander.rb
70
71
  - lib/sponges/configuration.rb
@@ -75,6 +76,7 @@ files:
75
76
  - lib/sponges/store.rb
76
77
  - lib/sponges/supervisor.rb
77
78
  - lib/sponges/version.rb
79
+ - lib/sponges/worker.rb
78
80
  homepage: http://af83.github.com/sponges
79
81
  licenses: []
80
82
  metadata: {}