resque 1.9.10 → 1.10.0

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,12 @@
1
+ ## 1.10.0 (2010-08-23)
2
+
3
+ * Support redis:// string format in `Resque.redis=`
4
+ * Using new cross-platform JSON gem.
5
+ * Added `after_enqueue` plugin hook.
6
+ * Added `shutdown?` method which can be overridden.
7
+ * Added support for the "leftright" gem when running tests.
8
+ * Grammarfix: In the README
9
+
1
10
  ## 1.9.10 (2010-08-06)
2
11
 
3
12
  * Bugfix: before_fork should get passed the job
@@ -9,8 +9,8 @@ Background jobs can be any Ruby class or module that responds to
9
9
  jobs or you can create new classes specifically to do work. Or, you
10
10
  can do both.
11
11
 
12
- Resque is heavily inspired by DelayedJob (which rocks) and is
13
- comprised of three parts:
12
+ Resque is heavily inspired by DelayedJob (which rocks) and comprises
13
+ three parts:
14
14
 
15
15
  1. A Ruby library for creating, querying, and processing jobs
16
16
  2. A Rake task for starting a worker which processes jobs
@@ -26,14 +26,23 @@ module Resque
26
26
  # Accepts:
27
27
  # 1. A 'hostname:port' string
28
28
  # 2. A 'hostname:port:db' string (to select the Redis db)
29
- # 3. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
29
+ # 3. A 'hostname:port/namespace' string (to set the Redis namespace)
30
+ # 4. A redis URL string 'redis://host:port'
31
+ # 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
30
32
  # or `Redis::Namespace`.
31
33
  def redis=(server)
32
34
  if server.respond_to? :split
33
- host, port, db = server.split(':')
34
- redis = Redis.new(:host => host, :port => port,
35
- :thread_safe => true, :db => db)
36
- @redis = Redis::Namespace.new(:resque, :redis => redis)
35
+ if server =~ /redis\:\/\//
36
+ redis = Redis.connect(:url => server)
37
+ else
38
+ server, namespace = server.split('/', 2)
39
+ host, port, db = server.split(':')
40
+ redis = Redis.new(:host => host, :port => port,
41
+ :thread_safe => true, :db => db)
42
+ end
43
+ namespace ||= :resque
44
+
45
+ @redis = Redis::Namespace.new(namespace, :redis => redis)
37
46
  elsif server.respond_to? :namespace=
38
47
  @redis = server
39
48
  else
@@ -48,7 +48,11 @@ module Resque
48
48
  raise NoClassError.new("Jobs must be given a class.")
49
49
  end
50
50
 
51
- Resque.push(queue, :class => klass.to_s, :args => args)
51
+ ret = Resque.push(queue, :class => klass.to_s, :args => args)
52
+ Plugin.after_enqueue_hooks(klass).each do |hook|
53
+ klass.send(hook, *args)
54
+ end
55
+ ret
52
56
  end
53
57
 
54
58
  # Removes a job from a queue. Expects a string queue name, a
@@ -42,5 +42,10 @@ module Resque
42
42
  def failure_hooks(job)
43
43
  job.methods.grep(/^on_failure/).sort
44
44
  end
45
+
46
+ # Given an object, returns a list `after_enqueue` hook names.
47
+ def after_enqueue_hooks(job)
48
+ job.methods.grep(/^after_enqueue/).sort
49
+ end
45
50
  end
46
51
  end
@@ -27,7 +27,7 @@
27
27
 
28
28
  <% else %>
29
29
 
30
- <% workers = resque.working %>
30
+ <% workers = resque.working.reject { |w| w.idle? } %>
31
31
  <h1 class='wi'><%= workers.size %> of <%= resque.workers.size %> Workers Working</h1>
32
32
  <p class='intro'>The list below contains all workers which are currently running a job.</p>
33
33
  <table class='workers'>
@@ -45,7 +45,6 @@
45
45
 
46
46
  <% for worker in workers.sort_by { |w| w.job['run_at'] ? w.job['run_at'] : '' } %>
47
47
  <% job = worker.job %>
48
- <% next if worker.idle? %>
49
48
 
50
49
  <tr>
51
50
  <td class='icon'><img src="<%=u state = worker.state %>.png" alt="<%= state %>" title="<%= state %>"></td>
@@ -1,3 +1,3 @@
1
1
  module Resque
2
- Version = VERSION = '1.9.10'
2
+ Version = VERSION = '1.10.0'
3
3
  end
@@ -108,7 +108,7 @@ module Resque
108
108
  startup
109
109
 
110
110
  loop do
111
- break if @shutdown
111
+ break if shutdown?
112
112
 
113
113
  if not @paused and job = reserve
114
114
  log "got: #{job.inspect}"
@@ -265,6 +265,11 @@ module Resque
265
265
  kill_child
266
266
  end
267
267
 
268
+ # Should this worker shutdown as soon as current job is finished?
269
+ def shutdown?
270
+ @shutdown
271
+ end
272
+
268
273
  # Kills the forked child immediately, without remorse. The job it
269
274
  # is processing will not be completed.
270
275
  def kill_child
@@ -228,6 +228,27 @@ context "Resque::Job on_failure" do
228
228
  end
229
229
  end
230
230
 
231
+ context "Resque::Job after_enqueue" do
232
+ include PerformJob
233
+
234
+ class ::AfterEnqueueJob
235
+ def self.after_enqueue_record_history(history)
236
+ history << :after_enqueue
237
+ end
238
+
239
+ def self.perform(history)
240
+ end
241
+ end
242
+
243
+ test "the after enqueue hook should run" do
244
+ history = []
245
+ @worker = Resque::Worker.new(:jobs)
246
+ Resque::Job.create(:jobs, AfterEnqueueJob, history)
247
+ @worker.work(0)
248
+ assert_equal history, [:after_enqueue], "after_enqueue was not run"
249
+ end
250
+ end
251
+
231
252
  context "Resque::Job all hooks" do
232
253
  include PerformJob
233
254
 
@@ -8,6 +8,13 @@ context "Resque" do
8
8
  Resque.push(:people, { 'name' => 'bob' })
9
9
  Resque.push(:people, { 'name' => 'mark' })
10
10
  end
11
+
12
+ test "can set a namespace through a url-like string" do
13
+ assert Resque.redis
14
+ assert_equal :resque, Resque.redis.namespace
15
+ Resque.redis = 'localhost:9736/namespace'
16
+ assert_equal 'namespace', Resque.redis.namespace
17
+ end
11
18
 
12
19
  test "can put jobs on a queue" do
13
20
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
@@ -222,4 +229,4 @@ context "Resque" do
222
229
  test "decode bad json" do
223
230
  assert_nil Resque.decode("{\"error\":\"Module not found \\u002\"}")
224
231
  end
225
- end
232
+ end
@@ -5,6 +5,11 @@ require 'test/unit'
5
5
  require 'rubygems'
6
6
  require 'resque'
7
7
 
8
+ begin
9
+ require 'leftright'
10
+ rescue LoadError
11
+ end
12
+
8
13
 
9
14
  #
10
15
  # make sure we can run redis
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 9
8
7
  - 10
9
- version: 1.9.10
8
+ - 0
9
+ version: 1.10.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Wanstrath
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-06 00:00:00 -07:00
17
+ date: 2010-08-23 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,7 @@ dependencies:
60
60
  type: :runtime
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: json_pure
63
+ name: json
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  requirements:
@@ -69,8 +69,8 @@ dependencies:
69
69
  segments:
70
70
  - 1
71
71
  - 4
72
- - 0
73
- version: 1.4.0
72
+ - 6
73
+ version: 1.4.6
74
74
  type: :runtime
75
75
  version_requirements: *id004
76
76
  description: " Resque is a Redis-backed Ruby library for creating background jobs,\n placing those jobs on multiple queues, and processing them later.\n\n Background jobs can be any Ruby class or module that responds to\n perform. Your existing classes can easily be converted to background\n jobs or you can create new classes specifically to do work. Or, you\n can do both.\n\n Resque is heavily inspired by DelayedJob (which rocks) and is\n comprised of three parts:\n\n * A Ruby library for creating, querying, and processing jobs\n * A Rake task for starting a worker which processes jobs\n * A Sinatra app for monitoring queues, jobs, and workers.\n"