opengotham_resque 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gitignore +2 -0
  2. data/.kick +26 -0
  3. data/HISTORY.md +142 -0
  4. data/LICENSE +20 -0
  5. data/README.markdown +794 -0
  6. data/Rakefile +112 -0
  7. data/bin/resque +57 -0
  8. data/bin/resque-web +23 -0
  9. data/config.ru +14 -0
  10. data/deps.rip +7 -0
  11. data/docs/HOOKS.md +121 -0
  12. data/docs/PLUGINS.md +93 -0
  13. data/examples/async_helper.rb +31 -0
  14. data/examples/demo/README.markdown +71 -0
  15. data/examples/demo/Rakefile +8 -0
  16. data/examples/demo/app.rb +38 -0
  17. data/examples/demo/config.ru +19 -0
  18. data/examples/demo/job.rb +22 -0
  19. data/examples/god/resque.god +53 -0
  20. data/examples/god/stale.god +26 -0
  21. data/examples/instance.rb +11 -0
  22. data/examples/monit/resque.monit +6 -0
  23. data/examples/simple.rb +30 -0
  24. data/init.rb +1 -0
  25. data/lib/resque.rb +287 -0
  26. data/lib/resque/errors.rb +10 -0
  27. data/lib/resque/failure.rb +66 -0
  28. data/lib/resque/failure/base.rb +61 -0
  29. data/lib/resque/failure/hoptoad.rb +132 -0
  30. data/lib/resque/failure/multiple.rb +48 -0
  31. data/lib/resque/failure/redis.rb +40 -0
  32. data/lib/resque/helpers.rb +63 -0
  33. data/lib/resque/job.rb +207 -0
  34. data/lib/resque/plugin.rb +46 -0
  35. data/lib/resque/server.rb +201 -0
  36. data/lib/resque/server/public/idle.png +0 -0
  37. data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
  38. data/lib/resque/server/public/jquery.relatize_date.js +95 -0
  39. data/lib/resque/server/public/poll.png +0 -0
  40. data/lib/resque/server/public/ranger.js +67 -0
  41. data/lib/resque/server/public/reset.css +48 -0
  42. data/lib/resque/server/public/style.css +81 -0
  43. data/lib/resque/server/public/working.png +0 -0
  44. data/lib/resque/server/test_helper.rb +19 -0
  45. data/lib/resque/server/views/error.erb +1 -0
  46. data/lib/resque/server/views/failed.erb +53 -0
  47. data/lib/resque/server/views/key_sets.erb +20 -0
  48. data/lib/resque/server/views/key_string.erb +11 -0
  49. data/lib/resque/server/views/layout.erb +44 -0
  50. data/lib/resque/server/views/next_more.erb +10 -0
  51. data/lib/resque/server/views/overview.erb +4 -0
  52. data/lib/resque/server/views/queues.erb +49 -0
  53. data/lib/resque/server/views/stats.erb +62 -0
  54. data/lib/resque/server/views/workers.erb +78 -0
  55. data/lib/resque/server/views/working.erb +69 -0
  56. data/lib/resque/stat.rb +53 -0
  57. data/lib/resque/tasks.rb +39 -0
  58. data/lib/resque/version.rb +3 -0
  59. data/lib/resque/worker.rb +478 -0
  60. data/tasks/redis.rake +159 -0
  61. data/tasks/resque.rake +2 -0
  62. data/test/job_hooks_test.rb +302 -0
  63. data/test/job_plugins_test.rb +209 -0
  64. data/test/plugin_test.rb +116 -0
  65. data/test/redis-test.conf +132 -0
  66. data/test/resque-web_test.rb +54 -0
  67. data/test/resque_test.rb +225 -0
  68. data/test/test_helper.rb +111 -0
  69. data/test/worker_test.rb +302 -0
  70. metadata +199 -0
@@ -0,0 +1,209 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Multiple plugins with multiple hooks" do
4
+ include PerformJob
5
+
6
+ module Plugin1
7
+ def before_perform_record_history1(history)
8
+ history << :before1
9
+ end
10
+ def after_perform_record_history1(history)
11
+ history << :after1
12
+ end
13
+ end
14
+
15
+ module Plugin2
16
+ def before_perform_record_history2(history)
17
+ history << :before2
18
+ end
19
+ def after_perform_record_history2(history)
20
+ history << :after2
21
+ end
22
+ end
23
+
24
+ class ManyBeforesJob
25
+ extend Plugin1
26
+ extend Plugin2
27
+ def self.perform(history)
28
+ history << :perform
29
+ end
30
+ end
31
+
32
+ test "hooks of each type are executed in alphabetical order" do
33
+ result = perform_job(ManyBeforesJob, history=[])
34
+ assert_equal true, result, "perform returned true"
35
+ assert_equal [:before1, :before2, :perform, :after1, :after2], history
36
+ end
37
+ end
38
+
39
+ context "Resque::Plugin ordering before_perform" do
40
+ include PerformJob
41
+
42
+ module BeforePerformPlugin
43
+ def before_perform1(history)
44
+ history << :before_perform1
45
+ end
46
+ end
47
+
48
+ class BeforePerformJob
49
+ extend BeforePerformPlugin
50
+ def self.perform(history)
51
+ history << :perform
52
+ end
53
+ def self.before_perform(history)
54
+ history << :before_perform
55
+ end
56
+ end
57
+
58
+ test "before_perform hooks are executed in order" do
59
+ result = perform_job(BeforePerformJob, history=[])
60
+ assert_equal true, result, "perform returned true"
61
+ assert_equal [:before_perform, :before_perform1, :perform], history
62
+ end
63
+ end
64
+
65
+ context "Resque::Plugin ordering after_perform" do
66
+ include PerformJob
67
+
68
+ module AfterPerformPlugin
69
+ def after_perform_record_history(history)
70
+ history << :after_perform1
71
+ end
72
+ end
73
+
74
+ class AfterPerformJob
75
+ extend AfterPerformPlugin
76
+ def self.perform(history)
77
+ history << :perform
78
+ end
79
+ def self.after_perform(history)
80
+ history << :after_perform
81
+ end
82
+ end
83
+
84
+ test "after_perform hooks are executed in order" do
85
+ result = perform_job(AfterPerformJob, history=[])
86
+ assert_equal true, result, "perform returned true"
87
+ assert_equal [:perform, :after_perform, :after_perform1], history
88
+ end
89
+ end
90
+
91
+ context "Resque::Plugin ordering around_perform" do
92
+ include PerformJob
93
+
94
+ module AroundPerformPlugin1
95
+ def around_perform1(history)
96
+ history << :around_perform_plugin1
97
+ yield
98
+ end
99
+ end
100
+
101
+ class AroundPerformJustPerformsJob
102
+ extend AroundPerformPlugin1
103
+ def self.perform(history)
104
+ history << :perform
105
+ end
106
+ end
107
+
108
+ test "around_perform hooks are executed before the job" do
109
+ result = perform_job(AroundPerformJustPerformsJob, history=[])
110
+ assert_equal true, result, "perform returned true"
111
+ assert_equal [:around_perform_plugin1, :perform], history
112
+ end
113
+
114
+ class AroundPerformJob
115
+ extend AroundPerformPlugin1
116
+ def self.perform(history)
117
+ history << :perform
118
+ end
119
+ def self.around_perform(history)
120
+ history << :around_perform
121
+ yield
122
+ end
123
+ end
124
+
125
+ test "around_perform hooks are executed in order" do
126
+ result = perform_job(AroundPerformJob, history=[])
127
+ assert_equal true, result, "perform returned true"
128
+ assert_equal [:around_perform, :around_perform_plugin1, :perform], history
129
+ end
130
+
131
+ module AroundPerformPlugin2
132
+ def around_perform2(history)
133
+ history << :around_perform_plugin2
134
+ yield
135
+ end
136
+ end
137
+
138
+ class AroundPerformJob2
139
+ extend AroundPerformPlugin1
140
+ extend AroundPerformPlugin2
141
+ def self.perform(history)
142
+ history << :perform
143
+ end
144
+ def self.around_perform(history)
145
+ history << :around_perform
146
+ yield
147
+ end
148
+ end
149
+
150
+ test "many around_perform are executed in order" do
151
+ result = perform_job(AroundPerformJob2, history=[])
152
+ assert_equal true, result, "perform returned true"
153
+ assert_equal [:around_perform, :around_perform_plugin1, :around_perform_plugin2, :perform], history
154
+ end
155
+
156
+ module AroundPerformDoesNotYield
157
+ def around_perform0(history)
158
+ history << :around_perform0
159
+ end
160
+ end
161
+
162
+ class AroundPerformJob3
163
+ extend AroundPerformPlugin1
164
+ extend AroundPerformPlugin2
165
+ extend AroundPerformDoesNotYield
166
+ def self.perform(history)
167
+ history << :perform
168
+ end
169
+ def self.around_perform(history)
170
+ history << :around_perform
171
+ yield
172
+ end
173
+ end
174
+
175
+ test "the job is aborted if an around_perform hook does not yield" do
176
+ result = perform_job(AroundPerformJob3, history=[])
177
+ assert_equal false, result, "perform returned false"
178
+ assert_equal [:around_perform, :around_perform0], history
179
+ end
180
+ end
181
+
182
+ context "Resque::Plugin ordering on_failure" do
183
+ include PerformJob
184
+
185
+ module OnFailurePlugin
186
+ def on_failure1(exception, history)
187
+ history << "#{exception.message} plugin"
188
+ end
189
+ end
190
+
191
+ class FailureJob
192
+ extend OnFailurePlugin
193
+ def self.perform(history)
194
+ history << :perform
195
+ raise StandardError, "oh no"
196
+ end
197
+ def self.on_failure(exception, history)
198
+ history << exception.message
199
+ end
200
+ end
201
+
202
+ test "on_failure hooks are executed in order" do
203
+ history = []
204
+ assert_raises StandardError do
205
+ perform_job(FailureJob, history)
206
+ end
207
+ assert_equal [:perform, "oh no", "oh no plugin"], history
208
+ end
209
+ end
@@ -0,0 +1,116 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ context "Resque::Plugin finding hooks" do
4
+ module SimplePlugin
5
+ extend self
6
+ def before_perform1; end
7
+ def before_perform; end
8
+ def before_perform2; end
9
+ def after_perform1; end
10
+ def after_perform; end
11
+ def after_perform2; end
12
+ def perform; end
13
+ def around_perform1; end
14
+ def around_perform; end
15
+ def around_perform2; end
16
+ def on_failure1; end
17
+ def on_failure; end
18
+ def on_failure2; end
19
+ end
20
+
21
+ test "before_perform hooks are found and sorted" do
22
+ assert_equal ["before_perform", "before_perform1", "before_perform2"], Resque::Plugin.before_hooks(SimplePlugin)
23
+ end
24
+
25
+ test "after_perform hooks are found and sorted" do
26
+ assert_equal ["after_perform", "after_perform1", "after_perform2"], Resque::Plugin.after_hooks(SimplePlugin)
27
+ end
28
+
29
+ test "around_perform hooks are found and sorted" do
30
+ assert_equal ["around_perform", "around_perform1", "around_perform2"], Resque::Plugin.around_hooks(SimplePlugin)
31
+ end
32
+
33
+ test "on_failure hooks are found and sorted" do
34
+ assert_equal ["on_failure", "on_failure1", "on_failure2"], Resque::Plugin.failure_hooks(SimplePlugin)
35
+ end
36
+ end
37
+
38
+ context "Resque::Plugin linting" do
39
+ module BadBefore
40
+ def self.before_perform; end
41
+ end
42
+ module BadAfter
43
+ def self.after_perform; end
44
+ end
45
+ module BadAround
46
+ def self.around_perform; end
47
+ end
48
+ module BadFailure
49
+ def self.on_failure; end
50
+ end
51
+
52
+ test "before_perform must be namespaced" do
53
+ begin
54
+ Resque::Plugin.lint(BadBefore)
55
+ assert false, "should have failed"
56
+ rescue Resque::Plugin::LintError => e
57
+ assert_equal "BadBefore.before_perform is not namespaced", e.message
58
+ end
59
+ end
60
+
61
+ test "after_perform must be namespaced" do
62
+ begin
63
+ Resque::Plugin.lint(BadAfter)
64
+ assert false, "should have failed"
65
+ rescue Resque::Plugin::LintError => e
66
+ assert_equal "BadAfter.after_perform is not namespaced", e.message
67
+ end
68
+ end
69
+
70
+ test "around_perform must be namespaced" do
71
+ begin
72
+ Resque::Plugin.lint(BadAround)
73
+ assert false, "should have failed"
74
+ rescue Resque::Plugin::LintError => e
75
+ assert_equal "BadAround.around_perform is not namespaced", e.message
76
+ end
77
+ end
78
+
79
+ test "on_failure must be namespaced" do
80
+ begin
81
+ Resque::Plugin.lint(BadFailure)
82
+ assert false, "should have failed"
83
+ rescue Resque::Plugin::LintError => e
84
+ assert_equal "BadFailure.on_failure is not namespaced", e.message
85
+ end
86
+ end
87
+
88
+ module GoodBefore
89
+ def self.before_perform1; end
90
+ end
91
+ module GoodAfter
92
+ def self.after_perform1; end
93
+ end
94
+ module GoodAround
95
+ def self.around_perform1; end
96
+ end
97
+ module GoodFailure
98
+ def self.on_failure1; end
99
+ end
100
+
101
+ test "before_perform1 is an ok name" do
102
+ Resque::Plugin.lint(GoodBefore)
103
+ end
104
+
105
+ test "after_perform1 is an ok name" do
106
+ Resque::Plugin.lint(GoodAfter)
107
+ end
108
+
109
+ test "around_perform1 is an ok name" do
110
+ Resque::Plugin.lint(GoodAround)
111
+ end
112
+
113
+ test "on_failure1 is an ok name" do
114
+ Resque::Plugin.lint(GoodFailure)
115
+ end
116
+ end
@@ -0,0 +1,132 @@
1
+ # Redis configuration file example
2
+
3
+ # By default Redis does not run as a daemon. Use 'yes' if you need it.
4
+ # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5
+ daemonize yes
6
+
7
+ # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
+ # You can specify a custom pid file location here.
9
+ pidfile ./test/redis-test.pid
10
+
11
+ # Accept connections on the specified port, default is 6379
12
+ port 9736
13
+
14
+ # If you want you can bind a single interface, if the bind option is not
15
+ # specified all the interfaces will listen for connections.
16
+ #
17
+ # bind 127.0.0.1
18
+
19
+ # Close the connection after a client is idle for N seconds (0 to disable)
20
+ timeout 300
21
+
22
+ # Save the DB on disk:
23
+ #
24
+ # save <seconds> <changes>
25
+ #
26
+ # Will save the DB if both the given number of seconds and the given
27
+ # number of write operations against the DB occurred.
28
+ #
29
+ # In the example below the behaviour will be to save:
30
+ # after 900 sec (15 min) if at least 1 key changed
31
+ # after 300 sec (5 min) if at least 10 keys changed
32
+ # after 60 sec if at least 10000 keys changed
33
+ save 900 1
34
+ save 300 10
35
+ save 60 10000
36
+
37
+ # The filename where to dump the DB
38
+ dbfilename dump.rdb
39
+
40
+ # For default save/load DB in/from the working directory
41
+ # Note that you must specify a directory not a file name.
42
+ dir ./test/
43
+
44
+ # Set server verbosity to 'debug'
45
+ # it can be one of:
46
+ # debug (a lot of information, useful for development/testing)
47
+ # notice (moderately verbose, what you want in production probably)
48
+ # warning (only very important / critical messages are logged)
49
+ loglevel debug
50
+
51
+ # Specify the log file name. Also 'stdout' can be used to force
52
+ # the demon to log on the standard output. Note that if you use standard
53
+ # output for logging but daemonize, logs will be sent to /dev/null
54
+ logfile stdout
55
+
56
+ # Set the number of databases. The default database is DB 0, you can select
57
+ # a different one on a per-connection basis using SELECT <dbid> where
58
+ # dbid is a number between 0 and 'databases'-1
59
+ databases 16
60
+
61
+ ################################# REPLICATION #################################
62
+
63
+ # Master-Slave replication. Use slaveof to make a Redis instance a copy of
64
+ # another Redis server. Note that the configuration is local to the slave
65
+ # so for example it is possible to configure the slave to save the DB with a
66
+ # different interval, or to listen to another port, and so on.
67
+
68
+ # slaveof <masterip> <masterport>
69
+
70
+ ################################## SECURITY ###################################
71
+
72
+ # Require clients to issue AUTH <PASSWORD> before processing any other
73
+ # commands. This might be useful in environments in which you do not trust
74
+ # others with access to the host running redis-server.
75
+ #
76
+ # This should stay commented out for backward compatibility and because most
77
+ # people do not need auth (e.g. they run their own servers).
78
+
79
+ # requirepass foobared
80
+
81
+ ################################### LIMITS ####################################
82
+
83
+ # Set the max number of connected clients at the same time. By default there
84
+ # is no limit, and it's up to the number of file descriptors the Redis process
85
+ # is able to open. The special value '0' means no limts.
86
+ # Once the limit is reached Redis will close all the new connections sending
87
+ # an error 'max number of clients reached'.
88
+
89
+ # maxclients 128
90
+
91
+ # Don't use more memory than the specified amount of bytes.
92
+ # When the memory limit is reached Redis will try to remove keys with an
93
+ # EXPIRE set. It will try to start freeing keys that are going to expire
94
+ # in little time and preserve keys with a longer time to live.
95
+ # Redis will also try to remove objects from free lists if possible.
96
+ #
97
+ # If all this fails, Redis will start to reply with errors to commands
98
+ # that will use more memory, like SET, LPUSH, and so on, and will continue
99
+ # to reply to most read-only commands like GET.
100
+ #
101
+ # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
102
+ # 'state' server or cache, not as a real DB. When Redis is used as a real
103
+ # database the memory usage will grow over the weeks, it will be obvious if
104
+ # it is going to use too much memory in the long run, and you'll have the time
105
+ # to upgrade. With maxmemory after the limit is reached you'll start to get
106
+ # errors for write operations, and this may even lead to DB inconsistency.
107
+
108
+ # maxmemory <bytes>
109
+
110
+ ############################### ADVANCED CONFIG ###############################
111
+
112
+ # Glue small output buffers together in order to send small replies in a
113
+ # single TCP packet. Uses a bit more CPU but most of the times it is a win
114
+ # in terms of number of queries per second. Use 'yes' if unsure.
115
+ glueoutputbuf yes
116
+
117
+ # Use object sharing. Can save a lot of memory if you have many common
118
+ # string in your dataset, but performs lookups against the shared objects
119
+ # pool so it uses more CPU and can be a bit slower. Usually it's a good
120
+ # idea.
121
+ #
122
+ # When object sharing is enabled (shareobjects yes) you can use
123
+ # shareobjectspoolsize to control the size of the pool used in order to try
124
+ # object sharing. A bigger pool size will lead to better sharing capabilities.
125
+ # In general you want this value to be at least the double of the number of
126
+ # very common strings you have in your dataset.
127
+ #
128
+ # WARNING: object sharing is experimental, don't enable this feature
129
+ # in production before of Redis 1.0-stable. Still please try this feature in
130
+ # your development environment so that we can test it better.
131
+ shareobjects no
132
+ shareobjectspoolsize 1024