prefork_engine 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9a157189f67ca8ff55ffe74a4936b211bb2155a
4
- data.tar.gz: fcfcc6aa5b119c87bc10ac30381d70c73aa78108
3
+ metadata.gz: d61cdcde16f3e999e4fb7335f9f799bec53dd4ec
4
+ data.tar.gz: aca8bdb8dde327a138f9d3291f998c3aecbdc004
5
5
  SHA512:
6
- metadata.gz: 0cba3a2971b80f3a916b8b650113c68432f183dfab274f7b490c281fe809dd128750150bbc8485c770344f4a470a41c6ccd31812207cf2e8411b4780569816e9
7
- data.tar.gz: b6fb8e007f2d5f74cef6c16b59354c64400df5c894778b59e00d171e1af3bc92ce1342bc2a4c5ead767367f15609b91eeada9c7795cf5ba97847b92366d0f3f9
6
+ metadata.gz: 7d9b252d0eee1b472bc81c01fd76b367ad354637466018dd6367f55780d17289056bbd3d13b45d726d07b3003d4fe2089c322ef94fafa7e8c604d80ae3c4e8c9
7
+ data.tar.gz: 099b01f4de3e829ef010bc34519ac2fcd7665ff8a77bb8f67a054d55756a80588cff5a5b3e4f8a52bddc886743736c490341e0198910f537b3557f8f5075a4f7
data/Changes CHANGED
@@ -1,3 +1,7 @@
1
+ 0.0.5 2014-12-19T16:39:31Z
2
+
3
+ - clean up code
4
+
1
5
  0.0.4 2014-12-16T16:45:52Z
2
6
 
3
7
  - sleep after EINTR for waiting for signal handler
@@ -26,13 +26,13 @@ class PreforkEngine
26
26
  @worker_pids = {}
27
27
  @delayed_task = nil
28
28
  @options["trap_signals"].each do |k,kv|
29
- Signal.trap(k) { |signo|
29
+ Signal.trap(k) do |signo|
30
30
  @signal_received = Signal.signame(signo)
31
- }
31
+ end
32
32
  end
33
- Signal.trap("CHLD") {
33
+ Signal.trap("CHLD") do
34
34
  #do nothing
35
- }
35
+ end
36
36
  end
37
37
 
38
38
  def start(&block)
@@ -44,9 +44,9 @@ class PreforkEngine
44
44
  # main loop
45
45
  while @signal_received.length == 0
46
46
  action = self._decide_action() if @_no_adjust_until <= Time.now.to_f
47
- if action > 0 then
47
+ if action > 0
48
48
  # start a new worker
49
- if @options["before_fork"] then
49
+ if @options["before_fork"]
50
50
  @options["before_fork"].call(self)
51
51
  end
52
52
  pid = nil
@@ -54,11 +54,11 @@ class PreforkEngine
54
54
  pid = fork
55
55
  rescue => e
56
56
  # fork failed
57
- warn "fork failed:#{e}";
57
+ warn "fork failed:#{e}"
58
58
  self._update_spawn_delay(@options["err_respawn_interval"])
59
59
  next
60
60
  end
61
- if pid == nil then
61
+ if pid == nil
62
62
  @in_child = true
63
63
  @options["trap_signals"].each do |k,kv|
64
64
  ## Signal.trap(k, 0) #XXX in rspec only?
@@ -70,30 +70,30 @@ class PreforkEngine
70
70
  exit!(true)
71
71
  end
72
72
  # parent
73
- if @options["after_fork"] then
73
+ if @options["after_fork"]
74
74
  @options["after_fork"].call(self)
75
75
  end
76
76
  @worker_pids[pid] = @generation
77
77
  self._update_spawn_delay(@options["spawn_interval"])
78
78
  end
79
- if r = self._wait() then
79
+ if r = self._wait()
80
80
  self._on_child_reap(r.pid, r.status)
81
- if @worker_pids.delete(r.pid) == @generation && r.status != 0 then
81
+ if @worker_pids.delete(r.pid) == @generation && r.status != 0
82
82
  self._update_spawn_delay(@options["err_respawn_interval"])
83
83
  end
84
84
  end
85
85
  end
86
86
 
87
87
  # send signals to workers
88
- if action = self._action_for(@signal_received) then
88
+ if action = self._action_for(@signal_received)
89
89
  sig = action[0]
90
90
  interval = action[1]
91
- if interval > 0 then
91
+ if interval > 0
92
92
  pids = @worker_pids.keys.sort
93
93
  @delayed_task = proc {
94
94
  pid = pids.shift
95
95
  Process.kill(sig, pid)
96
- if pids.empty? then
96
+ if pids.empty?
97
97
  @delayed_task = nil
98
98
  @delayed_task_at = nil
99
99
  else
@@ -125,7 +125,7 @@ class PreforkEngine
125
125
  end #_decide_action
126
126
 
127
127
  def _on_child_reap(pid,status)
128
- if @options["on_child_reap"] then
128
+ if @options["on_child_reap"]
129
129
  @options["on_child_reap"].call(pid,status)
130
130
  end
131
131
  end
@@ -133,7 +133,7 @@ class PreforkEngine
133
133
  def _handle_delayed_task
134
134
  while true
135
135
  return nil if !@delayed_task
136
- timeleft = @delayed_task_at - Time.now.to_f;
136
+ timeleft = @delayed_task_at - Time.now.to_f
137
137
  return timeleft if timeleft > 0
138
138
  @delayed_task.call
139
139
  end
@@ -149,8 +149,8 @@ class PreforkEngine
149
149
  def wait_all_children
150
150
  #XXX todo timeout
151
151
  while !@worker_pids.keys.empty?
152
- if r = self._wait() then
153
- if @worker_pids.delete(r.pid) then
152
+ if r = self._wait()
153
+ if @worker_pids.delete(r.pid)
154
154
  self._on_child_reap(r.pid, r.status)
155
155
  end
156
156
  end
@@ -168,7 +168,7 @@ class PreforkEngine
168
168
  delayed_fork_sleep = self._decide_action > 0 ? [@_no_adjust_until - Time.now.to_f,0].max : nil
169
169
  sleep_secs = [delayed_task_sleep,delayed_fork_sleep,self._max_wait].select {|v| v != nil}
170
170
  begin
171
- if sleep_secs.min != nil then
171
+ if sleep_secs.min != nil
172
172
  sleep(sleep_secs.min)
173
173
  # nonblock
174
174
  return Process.wait3(1)
@@ -1,3 +1,3 @@
1
1
  class PreforkEngine
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefork_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Nagano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler