sponges 0.5.0.2.pre → 0.5.0.3.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,11 +55,12 @@ module Sponges
55
55
 
56
56
  def handler_chld(signal)
57
57
  for_supervisor do
58
+ return if stopping?
58
59
  store.children_pids.each do |pid|
59
60
  begin
60
61
  if dead = Process.waitpid(pid.to_i, Process::WNOHANG)
61
- Sponges.logger.warn "Child #{dead} died. Restarting a new one..."
62
62
  store.delete_children dead
63
+ Sponges.logger.warn "Child #{dead} died. Restarting a new one..."
63
64
  Sponges::Hook.on_chld
64
65
  fork_children
65
66
  end
@@ -71,24 +72,20 @@ module Sponges
71
72
  end
72
73
 
73
74
  def handler_int(signal)
74
- Sponges.logger.info "Supervisor received #{signal} signal."
75
- kill_them_all(signal)
76
- Process.waitall
77
- Sponges.logger.info "Children shutdown complete."
78
- Sponges.logger.info "Supervisor shutdown. Exiting..."
79
- store.clear(name)
80
- exit
81
- rescue Errno::ESRCH, Errno::ECHILD, SignalException => e
82
- # Don't panic
75
+ for_supervisor do
76
+ @stopping = true
77
+ Sponges.logger.info "Supervisor received #{signal} signal."
78
+ kill_them_all(signal) and shutdown
79
+ end
83
80
  end
84
81
 
85
82
  alias handler_quit handler_int
86
83
  alias handler_term handler_int
87
84
 
88
85
  def kill_them_all(signal)
89
- store.children_pids.each do |pid|
90
- kill_one(pid.to_i, signal)
91
- end
86
+ store.children_pids.map do |pid|
87
+ Thread.new { kill_one(pid.to_i, signal) }
88
+ end.each &:join
92
89
  end
93
90
 
94
91
  def kill_one(pid, signal)
@@ -101,6 +98,15 @@ module Sponges
101
98
  end
102
99
  end
103
100
 
101
+ def shutdown
102
+ Process.waitall
103
+ Sponges.logger.info "Children shutdown complete.", "Supervisor shutdown. Exiting..."
104
+ store.clear(name)
105
+ exit
106
+ rescue Errno::ESRCH, Errno::ECHILD, SignalException => e
107
+ # Don't panic
108
+ end
109
+
104
110
  def fork_children
105
111
  name = children_name
106
112
  pid = fork do
@@ -112,5 +118,9 @@ module Sponges
112
118
  Sponges.logger.info "Supervisor create a child with #{pid} pid."
113
119
  store.add_children pid
114
120
  end
121
+
122
+ def stopping?
123
+ @stopping
124
+ end
115
125
  end
116
126
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Sponges
3
- VERSION = "0.5.0.2.pre"
3
+ VERSION = "0.5.0.3.pre"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sponges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.2.pre
4
+ version: 0.5.0.3.pre
5
5
  prerelease: 8
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: boson
@@ -107,3 +107,4 @@ signing_key:
107
107
  specification_version: 3
108
108
  summary: Turn any ruby object to a daemon controlling an army of sponges.
109
109
  test_files: []
110
+ has_rdoc: