resque-mongo 1.8.1 → 1.9.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +70 -0
- data/README.markdown +7 -2
- data/Rakefile +25 -30
- data/lib/resque.rb +9 -10
- data/lib/resque/failure/hoptoad.rb +2 -2
- data/lib/resque/failure/mongo.rb +3 -3
- data/lib/resque/failure/multiple.rb +11 -5
- data/lib/resque/job.rb +2 -1
- data/lib/resque/server.rb +2 -2
- data/lib/resque/server/test_helper.rb +1 -1
- data/lib/resque/server/views/failed.erb +8 -4
- data/lib/resque/server/views/layout.erb +1 -1
- data/lib/resque/server/views/stats.erb +2 -2
- data/lib/resque/tasks.rb +1 -1
- data/lib/resque/version.rb +1 -1
- data/lib/resque/worker.rb +1 -1
- data/tasks/redis.rake +3 -3
- data/test/job_hooks_test.rb +14 -14
- data/test/job_plugins_test.rb +29 -8
- data/test/plugin_test.rb +8 -8
- data/test/redis-test.conf +0 -17
- data/test/resque-web_test.rb +0 -20
- metadata +47 -73
- data/.gitignore +0 -3
- data/.kick +0 -26
- data/CONTRIBUTORS +0 -32
- data/config.ru +0 -14
- data/deps.rip +0 -8
- data/docs/HOOKS.md +0 -121
- data/docs/PLUGINS.md +0 -93
- data/examples/async_helper.rb +0 -31
- data/examples/demo/README.markdown +0 -71
- data/examples/demo/Rakefile +0 -8
- data/examples/demo/app.rb +0 -38
- data/examples/demo/config.ru +0 -19
- data/examples/demo/job.rb +0 -22
- data/examples/god/resque.god +0 -53
- data/examples/god/stale.god +0 -26
- data/examples/instance.rb +0 -11
- data/examples/monit/resque.monit +0 -6
- data/examples/simple.rb +0 -30
- data/init.rb +0 -1
data/.gitignore
DELETED
data/.kick
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# take control of the growl notifications
|
2
|
-
module GrowlHacks
|
3
|
-
def growl(type, subject, body, *args, &block)
|
4
|
-
case type
|
5
|
-
when Kicker::GROWL_NOTIFICATIONS[:succeeded]
|
6
|
-
puts subject = "Success"
|
7
|
-
body = body.split("\n").last
|
8
|
-
when Kicker::GROWL_NOTIFICATIONS[:failed]
|
9
|
-
subject = "Failure"
|
10
|
-
puts body
|
11
|
-
body = body.split("\n").last
|
12
|
-
else
|
13
|
-
return nil
|
14
|
-
end
|
15
|
-
super(type, subject, body, *args, &block)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Kicker.send :extend, GrowlHacks
|
20
|
-
|
21
|
-
# no logging
|
22
|
-
Kicker::Utils.module_eval do
|
23
|
-
def log(message)
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
data/CONTRIBUTORS
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
* Chris Wanstrath
|
2
|
-
* gravis
|
3
|
-
* scotttam
|
4
|
-
* John Barnette
|
5
|
-
* Mike Mangino
|
6
|
-
* Rob Hanlon
|
7
|
-
* Jason Amster
|
8
|
-
* Aaron Quint
|
9
|
-
* Adam Cooke
|
10
|
-
* Ashley Martens
|
11
|
-
* Matt Duncan
|
12
|
-
* Michael Dwan
|
13
|
-
* Daniel Ceballos
|
14
|
-
* Roman Heinrich
|
15
|
-
* Thibaut Barrère
|
16
|
-
* jgeiger
|
17
|
-
* Simon Rozet
|
18
|
-
* Dave Hoover
|
19
|
-
* Christos Trochalakis
|
20
|
-
* Ben VandenBos
|
21
|
-
* snusnu
|
22
|
-
* Arthur Zapparoli
|
23
|
-
* Ben Marini
|
24
|
-
* Brian P O'Rourke
|
25
|
-
* Jim Remsik and Les Hill
|
26
|
-
* Karel Minarik
|
27
|
-
* Luc Castera
|
28
|
-
* Masatomo Nakano
|
29
|
-
* Matt Palmer
|
30
|
-
* PJ Hyett
|
31
|
-
* Roland Moriz
|
32
|
-
* malomalo
|
data/config.ru
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'logger'
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift ::File.expand_path(::File.dirname(__FILE__) + '/lib')
|
5
|
-
require 'resque/server'
|
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
|
-
|
13
|
-
use Rack::ShowExceptions
|
14
|
-
run Resque::Server.new
|
data/deps.rip
DELETED
data/docs/HOOKS.md
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
Resque Hooks
|
2
|
-
============
|
3
|
-
|
4
|
-
You can customize Resque or write plugins using its hook API. In many
|
5
|
-
cases you can use a hook rather than mess with Resque's internals.
|
6
|
-
|
7
|
-
For a list of available plugins see
|
8
|
-
<http://wiki.github.com/defunkt/resque/plugins>.
|
9
|
-
|
10
|
-
|
11
|
-
Worker Hooks
|
12
|
-
------------
|
13
|
-
|
14
|
-
If you wish to have a Proc called before the worker forks for the
|
15
|
-
first time, you can add it in the initializer like so:
|
16
|
-
|
17
|
-
Resque.before_first_fork do
|
18
|
-
puts "Call me once before the worker forks the first time"
|
19
|
-
end
|
20
|
-
|
21
|
-
You can also run a hook before _every_ fork:
|
22
|
-
|
23
|
-
Resque.before_fork do |job|
|
24
|
-
puts "Call me before the worker forks"
|
25
|
-
end
|
26
|
-
|
27
|
-
The `before_fork` hook will be run in the **parent** process. So, be
|
28
|
-
careful - any changes you make will be permanent for the lifespan of
|
29
|
-
the worker.
|
30
|
-
|
31
|
-
And after forking:
|
32
|
-
|
33
|
-
Resque.after_fork do |job|
|
34
|
-
puts "Call me after the worker forks"
|
35
|
-
end
|
36
|
-
|
37
|
-
The `after_fork` hook will be run in the child process and is passed
|
38
|
-
the current job. Any changes you make, therefor, will only live as
|
39
|
-
long as the job currently being processes.
|
40
|
-
|
41
|
-
All worker hooks can also be set using a setter, e.g.
|
42
|
-
|
43
|
-
Resque.after_fork = proc { puts "called" }
|
44
|
-
|
45
|
-
|
46
|
-
Job Hooks
|
47
|
-
---------
|
48
|
-
|
49
|
-
Plugins can utilize job hooks to provide additional behavior. A job
|
50
|
-
hook is a method name in the following format:
|
51
|
-
|
52
|
-
HOOKNAME_IDENTIFIER
|
53
|
-
|
54
|
-
For example, a `before_perform` hook which adds locking may be defined
|
55
|
-
like this:
|
56
|
-
|
57
|
-
def before_perform_with_lock(*args)
|
58
|
-
set_lock!
|
59
|
-
end
|
60
|
-
|
61
|
-
Once this hook is made available to your job (either by way of
|
62
|
-
inheritence or `extend`), it will be run before the job's `perform`
|
63
|
-
method is called. Hooks of each type are executed in alphabetical order,
|
64
|
-
so `before_perform_a` will always be executed before `before_perform_b`.
|
65
|
-
An unnamed hook (`before_perform`) will be executed first.
|
66
|
-
|
67
|
-
The available hooks are:
|
68
|
-
|
69
|
-
* `before_perform`: Called with the job args before perform. If it raises
|
70
|
-
`Resque::Job::DontPerform`, the job is aborted. If other exceptions
|
71
|
-
are raised, they will be propagated up the the `Resque::Failure`
|
72
|
-
backend.
|
73
|
-
|
74
|
-
* `after_perform`: Called with the job args after it performs. Uncaught
|
75
|
-
exceptions will propagate up to the `Resque::Failure` backend.
|
76
|
-
|
77
|
-
* `around_perform`: Called with the job args. It is expected to yield in order
|
78
|
-
to perform the job (but is not required to do so). It may handle exceptions
|
79
|
-
thrown by `perform`, but any that are not caught will propagate up to the
|
80
|
-
`Resque::Failure` backend.
|
81
|
-
|
82
|
-
* `on_failure`: Called with the exception and job args if any exception occurs
|
83
|
-
while performing the job (or hooks).
|
84
|
-
|
85
|
-
Hooks are easily implemented with superclasses or modules. A superclass could
|
86
|
-
look something like this.
|
87
|
-
|
88
|
-
class LoggedJob
|
89
|
-
def self.before_perform_log_job(*args)
|
90
|
-
Logger.info "About to perform #{self} with #{args.inspect}"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class MyJob < LoggedJob
|
95
|
-
def self.perform(*args)
|
96
|
-
...
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
Modules are even better because jobs can use many of them.
|
101
|
-
|
102
|
-
module LoggedJob
|
103
|
-
def before_perform_log_job(*args)
|
104
|
-
Logger.info "About to perform #{self} with #{args.inspect}"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
module RetriedJob
|
109
|
-
def on_failure_retry(e, *args)
|
110
|
-
Logger.info "Performing #{self} caused an exception (#{e}). Retrying..."
|
111
|
-
Resque.enqueue self, *args
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
class MyJob
|
116
|
-
extend LoggedJob
|
117
|
-
extend RetriedJob
|
118
|
-
def self.perform(*args)
|
119
|
-
...
|
120
|
-
end
|
121
|
-
end
|
data/docs/PLUGINS.md
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
Resque Plugins
|
2
|
-
==============
|
3
|
-
|
4
|
-
Resque encourages plugin development. For a list of available plugins,
|
5
|
-
please see <http://wiki.github.com/defunkt/resque/plugins>.
|
6
|
-
|
7
|
-
The `docs/HOOKS.md` file included with Resque documents the available
|
8
|
-
hooks you can use to add or change Resque functionality. This document
|
9
|
-
describes best practice for plugins themselves.
|
10
|
-
|
11
|
-
|
12
|
-
Version
|
13
|
-
-------
|
14
|
-
|
15
|
-
Plugins should declare the major.minor version of Resque they are
|
16
|
-
known to work with explicitly in their README.
|
17
|
-
|
18
|
-
For example, if your plugin depends on features in Resque 2.1, please
|
19
|
-
list "Depends on Resque 2.1" very prominently near the beginning of
|
20
|
-
your README.
|
21
|
-
|
22
|
-
Because Resque uses [Semantic Versioning][sv], you can safely make the
|
23
|
-
following assumptions:
|
24
|
-
|
25
|
-
* Your plugin will work with 2.2, 2.3, etc - no methods will be
|
26
|
-
removed or changed, only added.
|
27
|
-
* Your plugin might not work with 3.0+, as APIs may change or be
|
28
|
-
removed.
|
29
|
-
|
30
|
-
|
31
|
-
Namespace
|
32
|
-
---------
|
33
|
-
|
34
|
-
All plugins should live under the `Resque::Plugins` module to avoid
|
35
|
-
clashing with first class Resque constants or other Ruby libraries.
|
36
|
-
|
37
|
-
Good:
|
38
|
-
|
39
|
-
* Resque::Plugins::Lock
|
40
|
-
* Resque::Plugins::FastRetry
|
41
|
-
|
42
|
-
Bad:
|
43
|
-
|
44
|
-
* Resque::Lock
|
45
|
-
* ResqueQueue
|
46
|
-
|
47
|
-
|
48
|
-
Gem Name
|
49
|
-
--------
|
50
|
-
|
51
|
-
Gem names should be in the format of `resque-FEATURE`, where `FEATURE`
|
52
|
-
succinctly describes the feature your plugin adds to Resque.
|
53
|
-
|
54
|
-
Good:
|
55
|
-
|
56
|
-
* resque-status
|
57
|
-
* resque-scheduler
|
58
|
-
|
59
|
-
Bad:
|
60
|
-
|
61
|
-
* multi-queue
|
62
|
-
* defunkt-resque-lock
|
63
|
-
|
64
|
-
|
65
|
-
Hooks
|
66
|
-
-----
|
67
|
-
|
68
|
-
Job hook names should be namespaced to work properly.
|
69
|
-
|
70
|
-
Good:
|
71
|
-
|
72
|
-
* before_perform_lock
|
73
|
-
* around_perform_check_status
|
74
|
-
|
75
|
-
Bad:
|
76
|
-
|
77
|
-
* before_perform
|
78
|
-
* on_failure
|
79
|
-
|
80
|
-
|
81
|
-
Lint
|
82
|
-
----
|
83
|
-
|
84
|
-
Plugins should test compliance to this document using the
|
85
|
-
`Resque::Plugin.lint` method.
|
86
|
-
|
87
|
-
For example:
|
88
|
-
|
89
|
-
assert_nothing_raised do
|
90
|
-
Resque::Plugin.lint(Resque::Plugins::Lock)
|
91
|
-
end
|
92
|
-
|
93
|
-
[sv]: http://semver.org/
|
data/examples/async_helper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# If you want to just call a method on an object in the background,
|
2
|
-
# we can easily add that functionality to Resque.
|
3
|
-
#
|
4
|
-
# This is similar to DelayedJob's `send_later`.
|
5
|
-
#
|
6
|
-
# Keep in mind that, unlike DelayedJob, only simple Ruby objects
|
7
|
-
# can be persisted.
|
8
|
-
#
|
9
|
-
# If it can be represented in JSON, it can be stored in a job.
|
10
|
-
|
11
|
-
# Here's our ActiveRecord class
|
12
|
-
class Repository < ActiveRecord::Base
|
13
|
-
# This will be called by a worker when a job needs to be processed
|
14
|
-
def self.perform(id, method, *args)
|
15
|
-
find(id).send(method, *args)
|
16
|
-
end
|
17
|
-
|
18
|
-
# We can pass this any Repository instance method that we want to
|
19
|
-
# run later.
|
20
|
-
def async(method, *args)
|
21
|
-
Resque.enqueue(Repository, id, method, *args)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Now we can call any method and have it execute later:
|
26
|
-
|
27
|
-
@repo.async(:update_disk_usage)
|
28
|
-
|
29
|
-
# or
|
30
|
-
|
31
|
-
@repo.async(:update_network_source_id, 34)
|
@@ -1,71 +0,0 @@
|
|
1
|
-
Resque Demo
|
2
|
-
-----------
|
3
|
-
|
4
|
-
This is a dirt simple Resque setup for you to play with.
|
5
|
-
|
6
|
-
|
7
|
-
### Starting the Demo App
|
8
|
-
|
9
|
-
Here's how to run the Sinatra app:
|
10
|
-
|
11
|
-
$ git clone git://github.com/defunkt/resque.git
|
12
|
-
$ cd resque/examples/demo
|
13
|
-
$ rackup config.ru
|
14
|
-
$ open http://localhost:9292/
|
15
|
-
|
16
|
-
Click 'Create New Job' a few times. You should see the number of
|
17
|
-
pending jobs rising.
|
18
|
-
|
19
|
-
|
20
|
-
### Starting the Demo Worker
|
21
|
-
|
22
|
-
Now in another shell terminal start the worker:
|
23
|
-
|
24
|
-
$ cd resque/examples/demo
|
25
|
-
$ VERBOSE=true QUEUE=default rake resque:work
|
26
|
-
|
27
|
-
You should see the following output:
|
28
|
-
|
29
|
-
*** Starting worker hostname:90185:default
|
30
|
-
*** got: (Job{default} | Demo::Job | [{}])
|
31
|
-
Processed a job!
|
32
|
-
*** done: (Job{default} | Demo::Job | [{}])
|
33
|
-
|
34
|
-
You can also use `VVERBOSE` (very verbose) if you want to see more:
|
35
|
-
|
36
|
-
$ VERBOSE=true QUEUE=default rake resque:work
|
37
|
-
*** Starting worker hostname:90399:default
|
38
|
-
** [05:55:09 2009-09-16] 90399: Registered signals
|
39
|
-
** [05:55:09 2009-09-16] 90399: Checking default
|
40
|
-
** [05:55:09 2009-09-16] 90399: Found job on default
|
41
|
-
** [05:55:09 2009-09-16] 90399: got: (Job{default} | Demo::Job | [{}])
|
42
|
-
** [05:55:09 2009-09-16] 90399: resque: Forked 90401 at 1253141709
|
43
|
-
** [05:55:09 2009-09-16] 90401: resque: Processing default since 1253141709
|
44
|
-
Processed a job!
|
45
|
-
** [05:55:10 2009-09-16] 90401: done: (Job{default} | Demo::Job | [{}])
|
46
|
-
|
47
|
-
Notice that our workers `require 'job'` in our `Rakefile`. This
|
48
|
-
ensures they have our app loaded and can access the job classes.
|
49
|
-
|
50
|
-
|
51
|
-
### Starting the Resque frontend
|
52
|
-
|
53
|
-
Great, now let's check out the Resque frontend. Either click on 'View
|
54
|
-
Resque' in your web browser or run:
|
55
|
-
|
56
|
-
$ open http://localhost:9292/resque/
|
57
|
-
|
58
|
-
You should see the Resque web frontend. 404 page? Don't forget the
|
59
|
-
trailing slash!
|
60
|
-
|
61
|
-
|
62
|
-
### config.ru
|
63
|
-
|
64
|
-
The `config.ru` shows you how to mount multiple Rack apps. Resque
|
65
|
-
should work fine on a subpath - feel free to load it up in your
|
66
|
-
Passenger app and protect it with some basic auth.
|
67
|
-
|
68
|
-
|
69
|
-
### That's it!
|
70
|
-
|
71
|
-
Click around, add some more queues, add more jobs, do whatever, have fun.
|
data/examples/demo/Rakefile
DELETED
data/examples/demo/app.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
require 'resque'
|
3
|
-
require 'job'
|
4
|
-
|
5
|
-
module Demo
|
6
|
-
class App < Sinatra::Base
|
7
|
-
get '/' do
|
8
|
-
info = Resque.info
|
9
|
-
out = "<html><head><title>Resque Demo</title></head><body>"
|
10
|
-
out << "<p>"
|
11
|
-
out << "There are #{info[:pending]} pending and "
|
12
|
-
out << "#{info[:processed]} processed jobs across #{info[:queues]} queues."
|
13
|
-
out << "</p>"
|
14
|
-
out << '<form method="POST">'
|
15
|
-
out << '<input type="submit" value="Create New Job"/>'
|
16
|
-
out << ' <a href="/resque/">View Resque</a>'
|
17
|
-
out << '</form>'
|
18
|
-
|
19
|
-
out << "<form action='/failing' method='POST''>"
|
20
|
-
out << '<input type="submit" value="Create Failing New Job"/>'
|
21
|
-
out << ' <a href="/resque/">View Resque</a>'
|
22
|
-
out << '</form>'
|
23
|
-
|
24
|
-
out << "</body></html>"
|
25
|
-
out
|
26
|
-
end
|
27
|
-
|
28
|
-
post '/' do
|
29
|
-
Resque.enqueue(Job, params)
|
30
|
-
redirect "/"
|
31
|
-
end
|
32
|
-
|
33
|
-
post '/failing' do
|
34
|
-
Resque.enqueue(FailingJob, params)
|
35
|
-
redirect "/"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|