spool 1.0.4 → 1.0.5

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: b153eb818306253d14aff97ee0883c8ab19dd4bb
4
- data.tar.gz: aadd1a7bdfdf4c8ffbe42b838059fd8ab14eb201
3
+ metadata.gz: c2ceedfd2a6bd4d1f326480ae51c527710282fad
4
+ data.tar.gz: b989fcc5b05800eb024673e14e1d60f3cc32a2cd
5
5
  SHA512:
6
- metadata.gz: 1779bb5745a04e15f872eff5fb71117281498f44cd20c4b76ddfc156771b448acaae46375774fe783a93d0b8fb65a25962f85e21f0dd51e598b7ab73d75a8974
7
- data.tar.gz: 8f042cf6b33a87c2262a9f528bfb8ffd9a17a835d9a6abf8c86d621cc34d9340ee9809f8a04974d4415d243c946c3b1798eaefbf8dca660ca5b531edd46546b9
6
+ metadata.gz: 2e47d2ccf341e8e0b3b077461e52ac395844fbf62288b468a7ce1949bb9688db74b40409f80c7fcdd903901f5c4b1fb965bb4af16f57b60b27c922400a7cf83c
7
+ data.tar.gz: c41197756bf9571ba469ca50cd1308a9b2cef7eb1077749c27a5c802c5464d889a5ddd4a40c8e7f1769bca599c4e65867c809d0328f2b03e9fe3d74ecc3e82db
@@ -56,16 +56,20 @@ module Spool
56
56
  logger.info(self.class) { "SPOOL START => #{format_processes}" }
57
57
 
58
58
  while running?
59
- action = actions_queue.pop
60
-
61
- if action
62
- logger.info(self.class) { "Starting action #{action[:name]} with params: [#{action[:args].join(', ')}]" }
63
- send action[:name], *action[:args]
64
- end
65
-
66
- if running?
67
- check_status
68
- sleep CHECK_TIMEOUT
59
+ begin
60
+ action = actions_queue.pop
61
+
62
+ if action
63
+ logger.info(self.class) { "Starting action #{action[:name]} with params: [#{action[:args].join(', ')}]" }
64
+ send action[:name], *action[:args]
65
+ end
66
+
67
+ if running?
68
+ check_status
69
+ sleep CHECK_TIMEOUT
70
+ end
71
+ rescue Exception => e
72
+ log_error e
69
73
  end
70
74
  end
71
75
 
@@ -98,7 +102,7 @@ module Spool
98
102
  working_processes << Spawner.spawn(configuration)
99
103
  end
100
104
 
101
- logger.info(self.class) { "Status after new childrens => #{format_processes}}" }
105
+ logger.info(self.class) { "Status after new childrens => #{format_processes}" }
102
106
  elsif configuration.processes < working_processes.count
103
107
  count_to_kill = working_processes.count - configuration.processes
104
108
  logger.info(self.class) { "Killing #{count_to_kill} children. Current state => #{format_processes}" }
@@ -107,9 +111,6 @@ module Spool
107
111
 
108
112
  logger.info(self.class) { "After killing childers. Current State => #{format_processes}" }
109
113
  end
110
-
111
- rescue Exception => e
112
- log_error e
113
114
  end
114
115
 
115
116
  def _incr(count=1)
@@ -130,15 +131,12 @@ module Spool
130
131
  stop_processes working_processes
131
132
  end
132
133
 
133
- def _stop(timeout=0)
134
+ def _stop
134
135
  logger.info(self.class) { "SPOOL STOP" }
135
136
 
136
137
  stop_processes working_processes
137
- Timeout.timeout(timeout) { wait_for_stopped all_processes }
138
- rescue Timeout::Error
139
- logger.error(self.class) { "ERROR IN SPOOL STOP. Timeout error" }
140
- ensure
141
- _stop!
138
+ wait_for_stopped all_processes
139
+
142
140
  @running = false
143
141
  end
144
142
 
@@ -154,11 +152,9 @@ module Spool
154
152
  end
155
153
 
156
154
  wait_for_stopped all_processes
157
-
158
- working_processes.clear
159
- zombie_processes.clear
160
-
155
+
161
156
  File.delete configuration.pid_file if File.exist? configuration.pid_file
157
+
162
158
  @running = false
163
159
  end
164
160
 
@@ -179,6 +175,8 @@ module Spool
179
175
  while processes_list.any?(&:alive?)
180
176
  sleep 0.01
181
177
  end
178
+
179
+ clear_dead_processes
182
180
  end
183
181
 
184
182
  def check_processes_to_restart
@@ -1,3 +1,3 @@
1
1
  module Spool
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
@@ -21,6 +21,7 @@ describe Spool::Pool do
21
21
  while pool.all_processes.count < pool.configuration.processes
22
22
  sleep 0.01
23
23
  end
24
+ sleep 0.1
24
25
  end
25
26
  end
26
27
 
@@ -119,22 +120,24 @@ describe Spool::Pool do
119
120
  pool.all_processes.each { |p| p.must_be :alive?}
120
121
  end
121
122
 
122
- it 'Stop with timeout' do
123
+ it 'Stop waits for children to die gracefully' do
123
124
  pool = start_pool do
124
125
  processes 1
125
- command 'ruby -e "Signal.trap(:QUIT) { puts :quit; sleep 5; exit 0 }; loop { sleep 1 }"'
126
+ command 'ruby -e "Signal.trap(:QUIT) { sleep 2; exit 0 }; loop { sleep 1 }"'
126
127
  stop_signal :QUIT
127
128
  end
128
129
 
130
+ sleep 1
131
+
129
132
  process = pool.all_processes[0]
130
-
133
+
131
134
  Benchmark.realtime do
132
- pool.stop 0.1
135
+ pool.stop
133
136
  while pool.running?
134
137
  sleep SLEEP_TIME
135
138
  end
136
- end.must_be :<, 1
137
-
139
+ end.must_be :>, 2
140
+
138
141
  pool.must_be :stopped?
139
142
  pool.all_processes.must_be_empty
140
143
  process.wont_be :alive?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datacenter