resque 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of resque might be problematic. Click here for more details.

data/HISTORY.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.2.1 (2009-12-07)
2
+
3
+ * Added `rake resque:workers` task for starting multiple workers.
4
+ * 1.9.x compatibility
5
+ * Bugfix: Yajl decoder doesn't care about valid UTF-8
6
+ * config.ru loads RESQUECONFIG if the ENV variable is set.
7
+ * `resque-web` now sets RESQUECONFIG
8
+ * Job objects know if they are equal.
9
+ * Jobs can be re-queued using `Job#recreate`
10
+
1
11
  ## 1.2.0 (2009-11-25)
2
12
 
3
13
  * If USR1 is sent and no child is found, shutdown.
data/README.markdown CHANGED
@@ -280,6 +280,21 @@ queues created on the fly, you can use a splat:
280
280
  Queues will be processed in alphabetical order.
281
281
 
282
282
 
283
+ ### Running Multiple Workers
284
+
285
+ At GitHub we use god to start and stop multiple workers. A sample god
286
+ configuration file is included under `examples/god`. We recommend this
287
+ method.
288
+
289
+ If you'd like to run multiple workers in development mode, you can do
290
+ so using the `resque:workers` rake task:
291
+
292
+ $ COUNT=5 QUEUE=* rake resque:workers
293
+
294
+ This will spawn five Resque workers, each in its own thread. Hitting
295
+ ctrl-c should be sufficient to stop them all.
296
+
297
+
283
298
  ### Forking
284
299
 
285
300
  On certain platforms, when a Resque worker reserves a job it
data/bin/resque-web CHANGED
@@ -30,18 +30,15 @@ Common options:
30
30
  --version Show version
31
31
  usage
32
32
  else
33
- if !ENV['CONFIG']&&ARGV[-1]&&ARGV[-1][0]!=?-&&(ARGV[-2]?ARGV[-2][0]!=?-:true)
33
+ if !ENV['RESQUECONFIG']&&ARGV[-1]&&ARGV[-1][0]!=?-&&(ARGV[-2]?ARGV[-2][0]!=?-:true)
34
34
  if File.file?(file = File.expand_path(ARGV[-1]))
35
35
  ARGV.delete_at(-1)
36
- ENV['CONFIG'] = file
36
+ ENV['RESQUECONFIG'] = file
37
37
  else
38
38
  abort "** Can't find #{file}"
39
39
  end
40
40
  end
41
41
 
42
- args = ARGV
43
- ENV['RUBYLIB'] = ENV['RUBYLIB'].to_s + ':' + __DIR__ + '/../lib'
44
- args.unshift '-e', 'require "resque";load ENV["CONFIG"] if ENV["CONFIG"]'
45
- args.push File.expand_path(File.dirname(__FILE__) + "/../config.ru")
46
- exec "rackup", *args
42
+ ARGV.push File.expand_path(File.dirname(__FILE__) + "/../config.ru")
43
+ exec "rackup", *ARGV
47
44
  end
data/config.ru CHANGED
@@ -4,5 +4,11 @@ require 'logger'
4
4
  $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
5
5
  require 'resque/server'
6
6
 
7
+ # Set the RESQUECONFIG env variable if you've a `resque.rb` or similar
8
+ # config file you want loaded on boot.
9
+ if ENV['RESQUECONFIG'] && File.exists?(File.expand_path(ENV['RESQUECONFIG']))
10
+ load File.expand_path(ENV['RESQUECONFIG'])
11
+ end
12
+
7
13
  use Rack::ShowExceptions
8
14
  run Resque::Server.new
@@ -21,7 +21,7 @@ module Resque
21
21
  return unless object
22
22
 
23
23
  if defined? Yajl
24
- Yajl::Parser.parse(object)
24
+ Yajl::Parser.parse(object, :check_utf8 => false)
25
25
  else
26
26
  JSON(object)
27
27
  end
data/lib/resque/job.rb CHANGED
@@ -81,10 +81,23 @@ module Resque
81
81
  :queue => queue
82
82
  end
83
83
 
84
+ # Creates an identical job, essentially placing this job back on
85
+ # the queue.
86
+ def recreate
87
+ self.class.create(queue, payload_class, *args)
88
+ end
89
+
84
90
  # String representation
85
91
  def inspect
86
92
  obj = @payload
87
93
  "(Job{%s} | %s | %s)" % [ @queue, obj['class'], obj['args'].inspect ]
88
94
  end
95
+
96
+ # Equality
97
+ def ==(other)
98
+ queue == other.queue &&
99
+ payload_class = other.payload_class &&
100
+ args == other.args
101
+ end
89
102
  end
90
103
  end
data/lib/resque/tasks.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  namespace :resque do
5
5
  task :setup
6
6
 
7
- desc "Start a Resque Ranger"
7
+ desc "Start a Resque worker"
8
8
  task :work => :setup do
9
9
  require 'resque'
10
10
 
@@ -23,4 +23,17 @@ namespace :resque do
23
23
 
24
24
  worker.work(ENV['INTERVAL'] || 5) # interval, will block
25
25
  end
26
+
27
+ desc "Start multiple Resque workers"
28
+ task :workers do
29
+ threads = []
30
+
31
+ ENV['COUNT'].to_i.times do
32
+ threads << Thread.new do
33
+ system "rake resque:work"
34
+ end
35
+ end
36
+
37
+ threads.each { |thread| thread.join }
38
+ end
26
39
  end
@@ -1,3 +1,3 @@
1
1
  module Resque
2
- Version = '1.2.0'
2
+ Version = '1.2.1'
3
3
  end
data/test/resque_test.rb CHANGED
@@ -25,6 +25,15 @@ context "Resque" do
25
25
  assert_equal '/tmp', job.args[1]
26
26
  end
27
27
 
28
+ test "can re-queue jobs" do
29
+ Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
30
+
31
+ job = Resque.reserve(:jobs)
32
+ job.recreate
33
+
34
+ assert_equal job, Resque.reserve(:jobs)
35
+ end
36
+
28
37
  test "can put jobs on a queue by way of an ivar" do
29
38
  assert_equal 0, Resque.size(:ivar)
30
39
  assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
@@ -47,6 +56,13 @@ context "Resque" do
47
56
  assert_equal '(Job{jobs} | SomeJob | [20, "/tmp"])', job.inspect
48
57
  end
49
58
 
59
+ test "jobs can test for equality" do
60
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
61
+ assert Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
62
+ job = Resque.reserve(:jobs)
63
+ assert_equal job, Resque.reserve(:jobs)
64
+ end
65
+
50
66
  test "can put jobs on a queue by way of a method" do
51
67
  assert_equal 0, Resque.size(:method)
52
68
  assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
data/test/test_helper.rb CHANGED
@@ -23,14 +23,19 @@ end
23
23
  #
24
24
 
25
25
  at_exit do
26
- unless $! || Test::Unit.run?
27
- status = Test::Unit::AutoRunner.run
28
- pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
29
- puts "Killing test redis server..."
30
- `rm -f #{dir}/dump.rdb`
31
- Process.kill("KILL", pid.to_i)
32
- exit status
26
+ next if $!
27
+
28
+ if defined?(MiniTest)
29
+ exit_code = MiniTest::Unit.new.run(ARGV)
30
+ else
31
+ exit_code = Test::Unit::AutoRunner.run
33
32
  end
33
+
34
+ pid = `ps -e -o pid,command | grep [r]edis-test`.split(" ")[0]
35
+ puts "Killing test redis server..."
36
+ `rm -f #{dir}/dump.rdb`
37
+ Process.kill("KILL", pid.to_i)
38
+ exit exit_code
34
39
  end
35
40
 
36
41
  puts "Starting redis for testing at localhost:9736..."
@@ -39,7 +44,7 @@ Resque.redis = 'localhost:9736'
39
44
 
40
45
 
41
46
  ##
42
- # test/spec/mini 2
47
+ # test/spec/mini 3
43
48
  # http://gist.github.com/25455
44
49
  # chris@ozmm.org
45
50
  #
@@ -54,6 +59,7 @@ def context(*args, &block)
54
59
  def self.setup(&block) define_method(:setup, &block) end
55
60
  def self.teardown(&block) define_method(:teardown, &block) end
56
61
  end
62
+ (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
57
63
  klass.class_eval &block
58
64
  end
59
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-25 00:00:00 -08:00
12
+ date: 2009-12-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency