resque-igo 1.12.7 → 1.12.8

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.12.0 (2011-02-03)
2
+
3
+ * Added pidfile writing from `rake resque:work`
4
+ * Added Worker#pid method
5
+ * Bugfix: Errors in failure backend are rescue'd
6
+ * Bugfix: Non-working workers no longer counted in "working" count
7
+ * Bugfix: Don't think resque-web is a worker
8
+
1
9
  ## 1.11.0 (2010-08-23)
2
10
 
3
11
  * Web UI: Group /workers page by hostnames
@@ -295,6 +295,13 @@ variable.
295
295
 
296
296
  $ VVERBOSE=1 QUEUE=file_serve rake environment resque:work
297
297
 
298
+ ### Process IDs (PIDs)
299
+
300
+ There are scenarios where it's helpful to record the PID of a resque
301
+ worker process. Use the PIDFILE option for easy access to the PID:
302
+
303
+ $ PIDFILE=./resque.pid QUEUE=file_serve rake environment resque:work
304
+
298
305
 
299
306
  ### Priorities and Queue Lists
300
307
 
data/Rakefile CHANGED
@@ -21,7 +21,6 @@ desc "Run the test suite"
21
21
  task :test do
22
22
  rg = command?(:rg)
23
23
  Dir['test/**/*_test.rb'].each do |f|
24
- #rg ? sh("rg #{f}") : ruby(f)
25
24
  ruby(f)
26
25
  end
27
26
  end
@@ -8,7 +8,6 @@ namespace :resque do
8
8
  task :work => :setup do
9
9
  require 'resque'
10
10
 
11
- worker = nil
12
11
  queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
13
12
 
14
13
  begin
@@ -19,6 +18,10 @@ namespace :resque do
19
18
  abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
20
19
  end
21
20
 
21
+ if ENV['PIDFILE']
22
+ File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid.to_s }
23
+ end
24
+
22
25
  worker.log "Starting worker #{worker}"
23
26
 
24
27
  worker.work(ENV['INTERVAL'] || 5) # interval, will block
@@ -1,3 +1,3 @@
1
1
  module Resque
2
- Version = VERSION = '1.12.7'
2
+ Version = VERSION = '1.12.8'
3
3
  end
@@ -68,7 +68,7 @@ module Resque
68
68
  # in alphabetical order. Queues can be dynamically added or
69
69
  # removed without needing to restart workers using this method.
70
70
  def initialize(*queues)
71
- @queues = queues
71
+ @queues = queues.map { |queue| queue.to_s.strip }
72
72
  validate_queues
73
73
  end
74
74
 
@@ -152,7 +152,11 @@ module Resque
152
152
  job.perform
153
153
  rescue Object => e
154
154
  log "#{job.inspect} failed: #{e.inspect}"
155
- job.fail(e)
155
+ begin
156
+ job.fail(e)
157
+ rescue Object => e
158
+ log "Received exception when reporting failure: #{e.inspect}"
159
+ end
156
160
  failed!
157
161
  else
158
162
  log "done: #{job.inspect}"
@@ -173,6 +177,10 @@ module Resque
173
177
  end
174
178
 
175
179
  nil
180
+ rescue Exception => e
181
+ log "Error reserving job: #{e.inspect}"
182
+ log e.backtrace.join("\n")
183
+ raise e
176
184
  end
177
185
 
178
186
  # Returns a list of queues to use when searching for a job.
@@ -435,7 +443,7 @@ module Resque
435
443
  # The string representation is the same as the id for this worker
436
444
  # instance. Can be used with `Worker.find`.
437
445
  def to_s
438
- @to_s ||= "#{hostname}:#{Process.pid}:#{@queues.join(',')}"
446
+ @to_s ||= "#{hostname}:#{pid}:#{@queues.join(',')}"
439
447
  end
440
448
  alias_method :id, :to_s
441
449
 
@@ -444,10 +452,15 @@ module Resque
444
452
  @hostname ||= `hostname`.chomp
445
453
  end
446
454
 
455
+ # Returns PID of running worker
456
+ def pid
457
+ @pid ||= Process.pid
458
+ end
459
+
447
460
  # Returns an array of string pids of all the other workers on this
448
461
  # machine. Useful when pruning dead workers on startup.
449
462
  def worker_pids
450
- `ps -A -o pid,command | grep [r]esque`.split("\n").map do |line|
463
+ `ps -A -o pid,command | grep [r]esque | grep -i "resque-web"`.split("\n").map do |line|
451
464
  line.split(' ')[0]
452
465
  end
453
466
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  context "Resque::Job before_perform" do
4
4
  include PerformJob
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  context "Multiple plugins with multiple hooks" do
4
4
  include PerformJob
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  context "Resque::Plugin finding hooks" do
4
4
  module SimplePlugin
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
  require 'resque/server/test_helper'
3
3
 
4
4
  # Root path test
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  context "Resque" do
4
4
  setup do
@@ -94,7 +94,6 @@ class NonUnique
94
94
  def self.perform(data)
95
95
  "I has a #{data}"
96
96
  end
97
-
98
97
  end
99
98
 
100
99
  class OtherUnique
@@ -134,6 +133,20 @@ class UniqueHydraJob
134
133
  @hydra = 100
135
134
  end
136
135
 
136
+ class BadFailureBackend < Resque::Failure::Base
137
+ def save
138
+ raise Exception.new("Failure backend error")
139
+ end
140
+ end
141
+
142
+ def with_failure_backend(failure_backend, &block)
143
+ previous_backend = Resque::Failure.backend
144
+ Resque::Failure.backend = failure_backend
145
+ yield block
146
+ ensure
147
+ Resque::Failure.backend = previous_backend
148
+ end
149
+
137
150
  #some redgreen fun
138
151
  # -*- coding: utf-8 -*-
139
152
  begin
@@ -179,6 +192,4 @@ begin
179
192
  end
180
193
  rescue LoadError
181
194
  puts "consider gem install redgreen"
182
- end
183
-
184
-
195
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  context "Resque::Worker" do
4
4
  setup do
@@ -24,6 +24,13 @@ context "Resque::Worker" do
24
24
  assert_equal('Extra Bad job!', failure['error'])
25
25
  end
26
26
 
27
+ test "does not allow exceptions from failure backend to escape" do
28
+ job = Resque::Job.new(:jobs, {})
29
+ with_failure_backend BadFailureBackend do
30
+ @worker.perform job
31
+ end
32
+ end
33
+
27
34
  test "fails uncompleted jobs on exit" do
28
35
  job = Resque::Job.new(:jobs, ['GoodJob', "blah"])
29
36
  @worker.working_on(job)
@@ -56,6 +63,12 @@ context "Resque::Worker" do
56
63
  assert_equal 2, Resque::Failure.count
57
64
  end
58
65
 
66
+ test "strips whitespace from queue names" do
67
+ queues = "critical, high, low".split(',')
68
+ worker = Resque::Worker.new(*queues)
69
+ assert_equal %w( critical high low ), worker.queues
70
+ end
71
+
59
72
  test "can work on multiple queues" do
60
73
  Resque::Job.create(:high, GoodJob)
61
74
  Resque::Job.create(:critical, GoodJob)
@@ -301,4 +314,8 @@ context "Resque::Worker" do
301
314
  workerA.work(0)
302
315
  assert $AFTER_FORK_CALLED
303
316
  end
317
+
318
+ test "returns PID of running process" do
319
+ assert_equal Process.pid, @worker.pid
320
+ end
304
321
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-igo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 41
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 12
9
- - 7
10
- version: 1.12.7
9
+ - 8
10
+ version: 1.12.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nathan D Acuff
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-31 00:00:00 -05:00
18
+ date: 2011-02-04 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency