resqued 0.7.4 → 0.7.6

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: 2d5c9debc1401bd8eba5b54ea6d6c2f9ad9787ac
4
- data.tar.gz: 2dc545b30cdc8a84c5d1264e4ba68126d087d232
3
+ metadata.gz: e4fb0bcb7e96b0df5bfa4dfa32340b99a5eea002
4
+ data.tar.gz: 76710f5182ec2f97a5136619a0ac573c40c6d96a
5
5
  SHA512:
6
- metadata.gz: 91b94be95c8bc28778f105505e075b56f5f70587a6b51efda99551e8b3503000354d31cc6fa16b10538653c39946a3a51d5c38e336a79dfd87afe9814f18fe31
7
- data.tar.gz: 659f8eca03013d49bcaef2641e8dcc7f56d6018b814924f01e5eef362dae9e5d4b05d971adf307739b3b810cf12fb9853e389ee8a08f4775d7dfa2cc4dcbc25f
6
+ metadata.gz: 9fddc96d14a8c6905d4b8220debe910d88a2a7bc8c6566b9b933117bb7b0f9752a0a339d0c59e6fb06f15894b6779894b776393679ef835f9e2f5afddfdf4649
7
+ data.tar.gz: dbea0b63b9e6c85593540cb76a2f74e427def5a34e492dcd8a4f9ab7f4d5d32b84078c92ad7c3b85b87e9e451cf5f721b2c6cb39cfe702a7194ccd709329eff2
@@ -19,7 +19,7 @@ module Resqued
19
19
  # Runs in the master process.
20
20
  def initialize(options)
21
21
  @config_paths = options.fetch(:config_paths)
22
- @running_workers = options.fetch(:running_workers) { [] }
22
+ @old_workers = options.fetch(:old_workers) { [] }.freeze
23
23
  @socket = options.fetch(:socket)
24
24
  @listener_id = options.fetch(:listener_id) { nil }
25
25
  end
@@ -31,7 +31,7 @@ module Resqued
31
31
  socket_fd = @socket.to_i
32
32
  ENV['RESQUED_SOCKET'] = socket_fd.to_s
33
33
  ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
34
- ENV['RESQUED_STATE'] = (@running_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
34
+ ENV['RESQUED_STATE'] = (@old_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
35
35
  ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
36
36
  ENV['RESQUED_MASTER_VERSION'] = Resqued::VERSION
37
37
  log "exec: #{Resqued::START_CTX['$0']} listener"
@@ -48,7 +48,7 @@ module Resqued
48
48
  options[:config_paths] = path.split(':')
49
49
  end
50
50
  if state = ENV['RESQUED_STATE']
51
- options[:running_workers] = state.split('||').map { |s| Hash[[:pid,:queue].zip(s.split('|'))] }
51
+ options[:old_workers] = state.split('||').map { |s| Hash[[:pid,:queue].zip(s.split('|'))] }
52
52
  end
53
53
  if listener_id = ENV['RESQUED_LISTENER_ID']
54
54
  options[:listener_id] = listener_id
@@ -127,8 +127,9 @@ module Resqued
127
127
 
128
128
  # Private: send a signal to all the workers.
129
129
  def kill_all(signal)
130
- log "kill -#{signal} #{running_workers.map { |r| r.pid }.inspect}"
131
- running_workers.each { |worker| worker.kill(signal) }
130
+ idle, running = partition_workers
131
+ log "kill -#{signal} #{running.map { |r| r.pid }.inspect}"
132
+ running.each { |worker| worker.kill(signal) }
132
133
  end
133
134
 
134
135
  # Private: all available workers
@@ -136,7 +137,12 @@ module Resqued
136
137
 
137
138
  # Private: just the running workers.
138
139
  def running_workers
139
- workers.select { |worker| ! worker.idle? }
140
+ partition_workers.last
141
+ end
142
+
143
+ # Private: Split the workers into [not-running, running]
144
+ def partition_workers
145
+ workers.partition { |worker| worker.idle? }
140
146
  end
141
147
 
142
148
  # Private.
@@ -204,7 +210,7 @@ module Resqued
204
210
  # Private.
205
211
  def init_workers(config)
206
212
  @workers = config.build_workers
207
- @running_workers.each do |running_worker|
213
+ @old_workers.each do |running_worker|
208
214
  if blocked_worker = @workers.detect { |worker| worker.idle? && worker.queue_key == running_worker[:queue] }
209
215
  blocked_worker.wait_for(running_worker[:pid].to_i)
210
216
  end
@@ -111,7 +111,7 @@ module Resqued
111
111
 
112
112
  def start_listener
113
113
  return if @current_listener || @listener_backoff.wait?
114
- @current_listener = ListenerProxy.new(:config_paths => @config_paths, :running_workers => all_listeners.map { |l| l.running_workers }.flatten, :listener_id => next_listener_id)
114
+ @current_listener = ListenerProxy.new(:config_paths => @config_paths, :old_workers => all_listeners.map { |l| l.running_workers }.flatten, :listener_id => next_listener_id)
115
115
  @current_listener.run
116
116
  listener_status @current_listener, 'start'
117
117
  @listener_backoff.started
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = '0.7.4'
2
+ VERSION = '0.7.6'
3
3
  end
@@ -13,6 +13,7 @@ module Resqued
13
13
  @config = options.fetch(:config)
14
14
  @interval = options[:interval]
15
15
  @backoff = Backoff.new
16
+ @pids = []
16
17
  end
17
18
 
18
19
  # Public: The pid of the worker process.
@@ -35,11 +36,13 @@ module Resqued
35
36
  def wait_for(pid)
36
37
  raise "Already running #{@pid} (can't wait for #{pid})" if @pid
37
38
  @self_started = false
39
+ @pids << pid
38
40
  @pid = pid
39
41
  end
40
42
 
41
43
  # Public: The old worker process finished!
42
44
  def finished!(process_status)
45
+ log :debug, "I (#{@pid}/#{@pids.inspect}/self_started=#{@self_started}/killed=#{@killed}) died like this: #{process_status}"
43
46
  @pid = nil
44
47
  @backoff.died unless @killed
45
48
  end
@@ -56,6 +59,7 @@ module Resqued
56
59
  @self_started = true
57
60
  @killed = false
58
61
  if @pid = fork
62
+ @pids << @pid
59
63
  # still in the listener
60
64
  log "Forked worker #{@pid}"
61
65
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resqued
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Burke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio