resqued 0.6.2 → 0.7.0

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: c970fdaa5c3ed98d5a08d4f8f9ae998a70fbb700
4
- data.tar.gz: 40b205f1d8c8da17189ccd14b9848656db3a6f10
3
+ metadata.gz: d66bf0dfa9299a44f871ae9835183600f6cc4e79
4
+ data.tar.gz: 318a6d0ec20aebbaf97260c3f2253394187ae2e1
5
5
  SHA512:
6
- metadata.gz: 4f3f703415a15b448da9d0372763ff789c532eae258018df43b471bab0a1eceec4482cd231feef99ec46929e50d29374fa5efb1c212bb56dab79ac0988e6e539
7
- data.tar.gz: 5e2dfa51990c8f441187ed713fbd1cc534d82d00d4e2185d44ef22b06b063e6d776eb2ecda3c68bac04345311b3942ae8fd83acba669e2b2b5412013c0212653
6
+ metadata.gz: cd97e21578a9cddaf82210459dc148790ed65ba92cd92c0d013764b03826df4683414ec1bfe56eeb73ebfe1bfe0854ba49826885a94c0c1ea38461e82a4affce
7
+ data.tar.gz: d8b4de064f53197605f7fc64bec9954a0bc8f4003bcd0c7334581043941e6e4762d42db0ee823a6c7ac085eaf6eb990be6d660b4dfd733bf877be09aa698ef5d
data/README.md CHANGED
@@ -37,8 +37,8 @@ To run the same fleet of workers with resqued, create a config file
37
37
  Another syntax for workers:
38
38
 
39
39
  worker_pool 5
40
- queue 'low', '20%'
41
- queue 'normal', '60%'
40
+ queue 'low', :percent => 20
41
+ queue 'normal', :percent => 60
42
42
  queue '*'
43
43
 
44
44
  This time, you'd end up with something similar to this:
@@ -96,8 +96,9 @@ You can configure the Resque worker in the `after_fork` block
96
96
  worker 'low', :interval => 30
97
97
 
98
98
  worker_pool 5, :interval => 1
99
- queue 'low', '20%'
100
- queue 'normal', 4
99
+ queue 'high', 'almosthigh'
100
+ queue 'low', :percent => 20
101
+ queue 'normal', :count => 4
101
102
  queue '*'
102
103
 
103
104
  before_fork do
@@ -114,11 +115,11 @@ You can configure the Resque worker in the `after_fork` block
114
115
  In this example, a Rails application is being set up with 7 workers:
115
116
  * high
116
117
  * low (interval = 30)
117
- * low, normal, * (interval = 1)
118
- * normal, * (interval = 1)
119
- * normal, * (interval = 1)
120
- * normal, * (interval = 1)
121
- * * (interval = 1)
118
+ * high, almosthigh, low, normal, * (interval = 1)
119
+ * high, almosthigh, normal, * (interval = 1)
120
+ * high, almosthigh, normal, * (interval = 1)
121
+ * high, almosthigh, normal, * (interval = 1)
122
+ * high, almosthigh, * (interval = 1)
122
123
 
123
124
  ## Multiple configurations
124
125
 
@@ -21,7 +21,7 @@ module Resqued
21
21
  end
22
22
 
23
23
  # Public: Define the queues worked by members of the worker pool.
24
- def queue(queue_name, concurrency = nil)
24
+ def queue(*queues)
25
25
  end
26
26
  end
27
27
  end
@@ -40,25 +40,24 @@ module Resqued
40
40
  #
41
41
  # queue 'one'
42
42
  # queue '*'
43
- # queue 'two', '10%'
44
- # queue 'three', 5
45
- # queue 'four', :percent => 10
43
+ # queue 'four-a', 'four-b', :percent => 10
46
44
  # queue 'five', :count => 5
47
- def queue(queue_name, concurrency = nil)
48
- @pool_queues[queue_name] =
49
- case concurrency
45
+ def queue(*queues)
46
+ options = queues.last.is_a?(Hash) ? queues.pop : {}
47
+ concurrency =
48
+ case options
50
49
  when Hash
51
- if percent = concurrency[:percent]
50
+ if percent = options[:percent]
52
51
  percent * 0.01
53
- elsif count = concurrency[:count]
52
+ elsif count = options[:count]
54
53
  count
55
54
  else
56
55
  1.0
57
56
  end
58
- when nil, ''; 1.0
59
- when /%$/; concurrency.chomp('%').to_i * 0.01
60
- else concurrency.to_i
57
+ else
58
+ 1.0
61
59
  end
60
+ queues.each { |queue| @pool_queues[queue] = concurrency }
62
61
  end
63
62
 
64
63
  private
@@ -4,6 +4,7 @@ require 'resqued/config'
4
4
  require 'resqued/logging'
5
5
  require 'resqued/procline_version'
6
6
  require 'resqued/sleepy'
7
+ require 'resqued/version'
7
8
  require 'resqued/worker'
8
9
 
9
10
  module Resqued
@@ -32,6 +33,7 @@ module Resqued
32
33
  ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
33
34
  ENV['RESQUED_STATE'] = (@running_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
34
35
  ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
36
+ ENV['RESQUED_MASTER_VERSION'] = Resqued::VERSION
35
37
  log "exec: #{Resqued::START_CTX['$0']} listener"
36
38
  Kernel.exec(Resqued::START_CTX['$0'], 'listener', socket_fd => socket_fd) # The hash at the end only works in new-ish (1.9+ or so) rubies. It's required for ruby 2.0.
37
39
  end
@@ -67,6 +69,7 @@ module Resqued
67
69
 
68
70
  config = Resqued::Config.new(@config_paths)
69
71
  config.before_fork
72
+ report_to_master("RUNNING")
70
73
 
71
74
  write_procline('running')
72
75
  init_workers(config)
@@ -67,16 +67,18 @@ module Resqued
67
67
 
68
68
  # Public: Check for updates on running worker information.
69
69
  def read_worker_status(options)
70
- on_finished = options[:on_finished]
70
+ on_activity = options[:on_activity]
71
71
  until @master_socket.nil?
72
72
  IO.select([@master_socket], nil, nil, 0) or return
73
- line = @master_socket.readline
74
- if line =~ /^\+(\d+),(.*)$/
73
+ case line = @master_socket.readline
74
+ when /^\+(\d+),(.*)$/
75
75
  worker_pids[$1] = $2
76
- elsif line =~ /^-(\d+)$/
76
+ when /^-(\d+)$/
77
77
  worker_pids.delete($1)
78
- on_finished.worker_finished($1) if on_finished
79
- elsif line == ''
78
+ on_activity.worker_finished($1) if on_activity
79
+ when /^RUNNING/
80
+ on_activity.listener_running(self) if on_activity
81
+ when ''
80
82
  break
81
83
  else
82
84
  log "Malformed data from listener: #{line.inspect}"
@@ -52,11 +52,12 @@ module Resqued
52
52
  when :HUP
53
53
  reopen_logs
54
54
  log "Restarting listener with new configuration and application."
55
- kill_listener(:QUIT)
55
+ prepare_new_listener
56
56
  when :USR2
57
57
  log "Pause job processing"
58
58
  @paused = true
59
- kill_listener(:QUIT)
59
+ kill_listener(:QUIT, @current_listener)
60
+ @current_listener = nil
60
61
  when :CONT
61
62
  log "Resume job processing"
62
63
  @paused = false
@@ -122,23 +123,53 @@ module Resqued
122
123
 
123
124
  def read_listeners
124
125
  all_listeners.each do |l|
125
- l.read_worker_status(:on_finished => self)
126
+ l.read_worker_status(:on_activity => self)
126
127
  end
127
128
  end
128
129
 
130
+ # Listener message: A worker just stopped working.
131
+ #
132
+ # Forwards the message to the other listeners.
129
133
  def worker_finished(pid)
130
134
  all_listeners.each do |other|
131
135
  other.worker_finished(pid)
132
136
  end
133
137
  end
134
138
 
135
- def kill_listener(signal)
136
- if @current_listener
137
- @current_listener.kill(signal)
138
- @current_listener = nil
139
+ # Listener message: A listener finished booting, and is ready to start workers.
140
+ #
141
+ # Promotes a booting listener to be the current listener.
142
+ def listener_running(listener)
143
+ if listener == @current_listener
144
+ kill_listener(:QUIT, @last_good_listener)
145
+ @last_good_listener = nil
146
+ else
147
+ # This listener didn't receive the last SIGQUIT we sent.
148
+ # (It was probably sent before the listener had set up its traps.)
149
+ # So kill it again. We have moved on.
150
+ kill_listener(:QUIT, listener)
139
151
  end
140
152
  end
141
153
 
154
+ # Private: Spin up a new listener.
155
+ #
156
+ # The old one will be killed when the new one is ready for workers.
157
+ def prepare_new_listener
158
+ if @last_good_listener
159
+ # The last_good_listener is still running because we got another HUP before the new listener finished booting.
160
+ # Keep the last_good_listener (where all the workers are) and kill the booting current_listener. We'll start a new one.
161
+ kill_listener(:QUIT, @current_listener)
162
+ else
163
+ @last_good_listener = @current_listener
164
+ end
165
+ # Indicate to `start_listener` that it should start a new listener.
166
+ @current_listener = nil
167
+ end
168
+
169
+ def kill_listener(signal, listener)
170
+ listener.kill(signal) if listener
171
+ end
172
+
142
173
  def kill_all_listeners(signal)
143
174
  all_listeners.each do |l|
144
175
  l.kill(signal)
@@ -1,3 +1,3 @@
1
1
  module Resqued
2
- VERSION = '0.6.2'
2
+ VERSION = '0.7.0'
3
3
  end
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.6.2
4
+ version: 0.7.0
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-10-17 00:00:00.000000000 Z
11
+ date: 2013-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio