resque 1.26.pre.0 → 1.26.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.

Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.md +29 -16
  3. data/README.markdown +60 -6
  4. data/Rakefile +4 -17
  5. data/bin/resque-web +4 -0
  6. data/lib/resque.rb +116 -16
  7. data/lib/resque/errors.rb +1 -0
  8. data/lib/resque/failure.rb +11 -5
  9. data/lib/resque/failure/multiple.rb +6 -1
  10. data/lib/resque/failure/redis.rb +13 -4
  11. data/lib/resque/failure/redis_multi_queue.rb +14 -6
  12. data/lib/resque/helpers.rb +5 -64
  13. data/lib/resque/job.rb +25 -79
  14. data/lib/resque/logging.rb +1 -1
  15. data/lib/resque/plugin.rb +22 -10
  16. data/lib/resque/server.rb +35 -7
  17. data/lib/resque/server/helpers.rb +1 -1
  18. data/lib/resque/server/views/failed.erb +1 -1
  19. data/lib/resque/server/views/failed_job.erb +3 -3
  20. data/lib/resque/server/views/failed_queues_overview.erb +3 -3
  21. data/lib/resque/server/views/workers.erb +2 -0
  22. data/lib/resque/server/views/working.erb +4 -5
  23. data/lib/resque/tasks.rb +7 -25
  24. data/lib/resque/vendor/utf8_util/utf8_util_19.rb +1 -0
  25. data/lib/resque/version.rb +1 -1
  26. data/lib/resque/worker.rb +225 -116
  27. metadata +68 -90
  28. data/test/airbrake_test.rb +0 -27
  29. data/test/dump.rdb +0 -0
  30. data/test/failure_base_test.rb +0 -15
  31. data/test/job_hooks_test.rb +0 -464
  32. data/test/job_plugins_test.rb +0 -230
  33. data/test/logging_test.rb +0 -24
  34. data/test/plugin_test.rb +0 -116
  35. data/test/redis-test-cluster.conf +0 -115
  36. data/test/redis-test.conf +0 -115
  37. data/test/resque-web_test.rb +0 -59
  38. data/test/resque_failure_redis_test.rb +0 -19
  39. data/test/resque_hook_test.rb +0 -165
  40. data/test/resque_test.rb +0 -278
  41. data/test/test_helper.rb +0 -198
  42. data/test/worker_test.rb +0 -1015
@@ -1,115 +0,0 @@
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
@@ -1,59 +0,0 @@
1
- require 'test_helper'
2
- require 'resque/server/test_helper'
3
-
4
- # Root path test
5
- context "on GET to /" do
6
- setup { get "/" }
7
-
8
- test "redirect to overview" do
9
- follow_redirect!
10
- end
11
- end
12
-
13
- # Global overview
14
- context "on GET to /overview" do
15
- setup { get "/overview" }
16
-
17
- test "should at least display 'queues'" do
18
- assert last_response.body.include?('Queues')
19
- end
20
- end
21
-
22
- # Working jobs
23
- context "on GET to /working" do
24
- setup { get "/working" }
25
-
26
- should_respond_with_success
27
- end
28
-
29
- # Failed
30
- context "on GET to /failed" do
31
- setup { get "/failed" }
32
-
33
- should_respond_with_success
34
- end
35
-
36
- # Stats
37
- context "on GET to /stats/resque" do
38
- setup { get "/stats/resque" }
39
-
40
- should_respond_with_success
41
- end
42
-
43
- context "on GET to /stats/redis" do
44
- setup { get "/stats/redis" }
45
-
46
- should_respond_with_success
47
- end
48
-
49
- context "on GET to /stats/resque" do
50
- setup { get "/stats/keys" }
51
-
52
- should_respond_with_success
53
- end
54
-
55
- context "also works with slash at the end" do
56
- setup { get "/working/" }
57
-
58
- should_respond_with_success
59
- end
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
- require 'resque/failure/redis'
3
-
4
- context "Resque::Failure::Redis" do
5
- setup do
6
- @bad_string = [39, 52, 127, 86, 93, 95, 39].map { |c| c.chr }.join
7
- exception = StandardError.exception(@bad_string)
8
- worker = Resque::Worker.new(:test)
9
- queue = "queue"
10
- payload = { "class" => Object, "args" => 3 }
11
- @redis_backend = Resque::Failure::Redis.new(exception, worker, queue, payload)
12
- end
13
-
14
- test 'cleans up bad strings before saving the failure, in order to prevent errors on the resque UI' do
15
- # test assumption: the bad string should not be able to round trip though JSON
16
- @redis_backend.save
17
- Resque::Failure::Redis.all # should not raise an error
18
- end
19
- end
@@ -1,165 +0,0 @@
1
- require 'test_helper'
2
- require 'tempfile'
3
-
4
- describe "Resque Hooks" do
5
- before do
6
- Resque.redis.flushall
7
-
8
- Resque.before_first_fork = nil
9
- Resque.before_fork = nil
10
- Resque.after_fork = nil
11
-
12
- @worker = Resque::Worker.new(:jobs)
13
-
14
- $called = false
15
-
16
- class CallNotifyJob
17
- def self.perform
18
- $called = true
19
- end
20
- end
21
- end
22
-
23
- it 'retrieving hooks if none have been set' do
24
- assert_equal [], Resque.before_first_fork
25
- assert_equal [], Resque.before_fork
26
- assert_equal [], Resque.after_fork
27
- end
28
-
29
- it 'it calls before_first_fork once' do
30
- counter = 0
31
-
32
- Resque.before_first_fork { counter += 1 }
33
- 2.times { Resque::Job.create(:jobs, CallNotifyJob) }
34
-
35
- assert_equal(0, counter)
36
- @worker.work(0)
37
- assert_equal(1, counter)
38
- end
39
-
40
- it 'it calls before_fork before each job' do
41
- counter = 0
42
-
43
- Resque.before_fork { counter += 1 }
44
- 2.times { Resque::Job.create(:jobs, CallNotifyJob) }
45
-
46
- assert_equal(0, counter)
47
- @worker.work(0)
48
- assert_equal(2, counter)
49
- end
50
-
51
- it 'it calls after_fork after each job' do
52
- skip("TRAAAVIS!!!!") if RUBY_VERSION == "1.8.7"
53
- # We have to stub out will_fork? to return true, which is going to cause an actual fork(). As such, the
54
- # exit!(true) will be called in Worker#work; to share state, use a tempfile
55
- file = Tempfile.new("resque_after_fork")
56
-
57
- begin
58
- File.open(file.path, "w") {|f| f.write(0)}
59
- Resque.after_fork do
60
- val = File.read(file).strip.to_i
61
- File.open(file.path, "w") {|f| f.write(val + 1)}
62
- end
63
- 2.times { Resque::Job.create(:jobs, CallNotifyJob) }
64
-
65
- val = File.read(file.path).strip.to_i
66
- assert_equal(0, val)
67
- @worker.stubs(:will_fork?).returns(true)
68
- @worker.work(0)
69
- val = File.read(file.path).strip.to_i
70
- assert_equal(2, val)
71
- ensure
72
- file.delete
73
- end
74
- end
75
-
76
- it 'it calls before_first_fork before forking' do
77
- Resque.before_first_fork { assert(!$called) }
78
-
79
- Resque::Job.create(:jobs, CallNotifyJob)
80
- @worker.work(0)
81
- end
82
-
83
- it 'it calls before_fork before forking' do
84
- Resque.before_fork { assert(!$called) }
85
-
86
- Resque::Job.create(:jobs, CallNotifyJob)
87
- @worker.work(0)
88
- end
89
-
90
- it 'it calls after_fork after forking' do
91
- Resque.after_fork { assert($called) }
92
-
93
- Resque::Job.create(:jobs, CallNotifyJob)
94
- @worker.work(0)
95
- end
96
-
97
- it 'it registers multiple before_first_forks' do
98
- first = false
99
- second = false
100
-
101
- Resque.before_first_fork { first = true }
102
- Resque.before_first_fork { second = true }
103
- Resque::Job.create(:jobs, CallNotifyJob)
104
-
105
- assert(!first && !second)
106
- @worker.work(0)
107
- assert(first && second)
108
- end
109
-
110
- it 'it registers multiple before_forks' do
111
- first = false
112
- second = false
113
-
114
- Resque.before_fork { first = true }
115
- Resque.before_fork { second = true }
116
- Resque::Job.create(:jobs, CallNotifyJob)
117
-
118
- assert(!first && !second)
119
- @worker.work(0)
120
- assert(first && second)
121
- end
122
-
123
- it 'flattens hooks on assignment' do
124
- first = false
125
- second = false
126
- Resque.before_fork = [Proc.new { first = true }, Proc.new { second = true }]
127
- Resque::Job.create(:jobs, CallNotifyJob)
128
-
129
- assert(!first && !second)
130
- @worker.work(0)
131
- assert(first && second)
132
- end
133
-
134
- it 'it registers multiple after_forks' do
135
- # We have to stub out will_fork? to return true, which is going to cause an actual fork(). As such, the
136
- # exit!(true) will be called in Worker#work; to share state, use a tempfile
137
- file = Tempfile.new("resque_after_fork_first")
138
- file2 = Tempfile.new("resque_after_fork_second")
139
- begin
140
- File.open(file.path, "w") {|f| f.write(1)}
141
- File.open(file2.path, "w") {|f| f.write(2)}
142
-
143
- Resque.after_fork do
144
- val = File.read(file.path).strip.to_i
145
- File.open(file.path, "w") {|f| f.write(val + 1)}
146
- end
147
-
148
- Resque.after_fork do
149
- val = File.read(file2.path).strip.to_i
150
- File.open(file2.path, "w") {|f| f.write(val + 1)}
151
- end
152
- Resque::Job.create(:jobs, CallNotifyJob)
153
-
154
- @worker.stubs(:will_fork?).returns(true)
155
- @worker.work(0)
156
- val = File.read(file.path).strip.to_i
157
- val2 = File.read(file2.path).strip.to_i
158
- assert_equal(val, 2)
159
- assert_equal(val2, 3)
160
- ensure
161
- file.delete
162
- file2.delete
163
- end
164
- end
165
- end
@@ -1,278 +0,0 @@
1
- require 'test_helper'
2
-
3
- context "Resque" do
4
- setup do
5
- Resque.redis.flushall
6
-
7
- Resque.push(:people, { 'name' => 'chris' })
8
- Resque.push(:people, { 'name' => 'bob' })
9
- Resque.push(:people, { 'name' => 'mark' })
10
- @original_redis = Resque.redis
11
- end
12
-
13
- teardown do
14
- Resque.redis = @original_redis
15
- end
16
-
17
- test "can set a namespace through a url-like string" do
18
- assert Resque.redis
19
- assert_equal :resque, Resque.redis.namespace
20
- Resque.redis = 'localhost:9736/namespace'
21
- assert_equal 'namespace', Resque.redis.namespace
22
- end
23
-
24
- test "redis= works correctly with a Redis::Namespace param" do
25
- new_redis = Redis.new(:host => "localhost", :port => 9736)
26
- new_namespace = Redis::Namespace.new("namespace", :redis => new_redis)
27
- Resque.redis = new_namespace
28
- assert_equal new_namespace, Resque.redis
29
-
30
- Resque.redis = 'localhost:9736/namespace'
31
- end
32
-
33
- test "can put jobs on a queue" do
34
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
35
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
36
- end
37
-
38
- test "can grab jobs off a queue" do
39
- Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
40
-
41
- job = Resque.reserve(:jobs)
42
-
43
- assert_kind_of Resque::Job, job
44
- assert_equal SomeJob, job.payload_class
45
- assert_equal 20, job.args[0]
46
- assert_equal '/tmp', job.args[1]
47
- end
48
-
49
- test "can re-queue jobs" do
50
- Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
51
-
52
- job = Resque.reserve(:jobs)
53
- job.recreate
54
-
55
- assert_equal job, Resque.reserve(:jobs)
56
- end
57
-
58
- test "can put jobs on a queue by way of an ivar" do
59
- assert_equal 0, Resque.size(:ivar)
60
- assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
61
- assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
62
-
63
- job = Resque.reserve(:ivar)
64
-
65
- assert_kind_of Resque::Job, job
66
- assert_equal SomeIvarJob, job.payload_class
67
- assert_equal 20, job.args[0]
68
- assert_equal '/tmp', job.args[1]
69
-
70
- assert Resque.reserve(:ivar)
71
- assert_equal nil, Resque.reserve(:ivar)
72
- end
73
-
74
- test "can remove jobs from a queue by way of an ivar" do
75
- assert_equal 0, Resque.size(:ivar)
76
- assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
77
- assert Resque.enqueue(SomeIvarJob, 30, '/tmp')
78
- assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
79
- assert Resque::Job.create(:ivar, 'blah-job', 20, '/tmp')
80
- assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
81
- assert_equal 5, Resque.size(:ivar)
82
-
83
- assert_equal 1, Resque.dequeue(SomeIvarJob, 30, '/tmp')
84
- assert_equal 4, Resque.size(:ivar)
85
- assert_equal 3, Resque.dequeue(SomeIvarJob)
86
- assert_equal 1, Resque.size(:ivar)
87
- end
88
-
89
- test "jobs have a nice #inspect" do
90
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
91
- job = Resque.reserve(:jobs)
92
- assert_equal '(Job{jobs} | SomeJob | [20, "/tmp"])', job.inspect
93
- end
94
-
95
- test "jobs can be destroyed" do
96
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
97
- assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
98
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
99
- assert Resque::Job.create(:jobs, 'BadJob', 30, '/tmp')
100
- assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
101
-
102
- assert_equal 5, Resque.size(:jobs)
103
- assert_equal 2, Resque::Job.destroy(:jobs, 'SomeJob')
104
- assert_equal 3, Resque.size(:jobs)
105
- assert_equal 1, Resque::Job.destroy(:jobs, 'BadJob', 30, '/tmp')
106
- assert_equal 2, Resque.size(:jobs)
107
- end
108
-
109
- test "jobs can test for equality" do
110
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
111
- assert Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
112
- assert_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
113
-
114
- assert Resque::Job.create(:jobs, 'SomeMethodJob', 20, '/tmp')
115
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
116
- assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
117
-
118
- assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
119
- assert Resque::Job.create(:jobs, 'SomeJob', 30, '/tmp')
120
- assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
121
- end
122
-
123
- test "can put jobs on a queue by way of a method" do
124
- assert_equal 0, Resque.size(:method)
125
- assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
126
- assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
127
-
128
- job = Resque.reserve(:method)
129
-
130
- assert_kind_of Resque::Job, job
131
- assert_equal SomeMethodJob, job.payload_class
132
- assert_equal 20, job.args[0]
133
- assert_equal '/tmp', job.args[1]
134
-
135
- assert Resque.reserve(:method)
136
- assert_equal nil, Resque.reserve(:method)
137
- end
138
-
139
- test "can define a queue for jobs by way of a method" do
140
- assert_equal 0, Resque.size(:method)
141
- assert Resque.enqueue_to(:new_queue, SomeMethodJob, 20, '/tmp')
142
-
143
- job = Resque.reserve(:new_queue)
144
- assert_equal SomeMethodJob, job.payload_class
145
- assert_equal 20, job.args[0]
146
- assert_equal '/tmp', job.args[1]
147
- end
148
-
149
- test "needs to infer a queue with enqueue" do
150
- assert_raises Resque::NoQueueError do
151
- Resque.enqueue(SomeJob, 20, '/tmp')
152
- end
153
- end
154
-
155
- test "validates job for queue presence" do
156
- assert_raises Resque::NoQueueError do
157
- Resque.validate(SomeJob)
158
- end
159
- end
160
-
161
- test "can put items on a queue" do
162
- assert Resque.push(:people, { 'name' => 'jon' })
163
- end
164
-
165
- test "can pull items off a queue" do
166
- assert_equal({ 'name' => 'chris' }, Resque.pop(:people))
167
- assert_equal({ 'name' => 'bob' }, Resque.pop(:people))
168
- assert_equal({ 'name' => 'mark' }, Resque.pop(:people))
169
- assert_equal nil, Resque.pop(:people)
170
- end
171
-
172
- test "knows how big a queue is" do
173
- assert_equal 3, Resque.size(:people)
174
-
175
- assert_equal({ 'name' => 'chris' }, Resque.pop(:people))
176
- assert_equal 2, Resque.size(:people)
177
-
178
- assert_equal({ 'name' => 'bob' }, Resque.pop(:people))
179
- assert_equal({ 'name' => 'mark' }, Resque.pop(:people))
180
- assert_equal 0, Resque.size(:people)
181
- end
182
-
183
- test "can peek at a queue" do
184
- assert_equal({ 'name' => 'chris' }, Resque.peek(:people))
185
- assert_equal 3, Resque.size(:people)
186
- end
187
-
188
- test "can peek multiple items on a queue" do
189
- assert_equal({ 'name' => 'bob' }, Resque.peek(:people, 1, 1))
190
-
191
- assert_equal([{ 'name' => 'bob' }, { 'name' => 'mark' }], Resque.peek(:people, 1, 2))
192
- assert_equal([{ 'name' => 'chris' }, { 'name' => 'bob' }], Resque.peek(:people, 0, 2))
193
- assert_equal([{ 'name' => 'chris' }, { 'name' => 'bob' }, { 'name' => 'mark' }], Resque.peek(:people, 0, 3))
194
- assert_equal({ 'name' => 'mark' }, Resque.peek(:people, 2, 1))
195
- assert_equal nil, Resque.peek(:people, 3)
196
- assert_equal [], Resque.peek(:people, 3, 2)
197
- end
198
-
199
- test "knows what queues it is managing" do
200
- assert_equal %w( people ), Resque.queues
201
- Resque.push(:cars, { 'make' => 'bmw' })
202
- assert_equal %w( cars people ).sort, Resque.queues.sort
203
- end
204
-
205
- test "queues are always a list" do
206
- Resque.redis.flushall
207
- assert_equal [], Resque.queues
208
- end
209
-
210
- test "can delete a queue" do
211
- Resque.push(:cars, { 'make' => 'bmw' })
212
- assert_equal %w( cars people ).sort, Resque.queues.sort
213
- Resque.remove_queue(:people)
214
- assert_equal %w( cars ), Resque.queues
215
- assert_equal nil, Resque.pop(:people)
216
- end
217
-
218
- test "keeps track of resque keys" do
219
- assert_equal ["queue:people", "queues"].sort, Resque.keys.sort
220
- end
221
-
222
- test "badly wants a class name, too" do
223
- assert_raises Resque::NoClassError do
224
- Resque::Job.create(:jobs, nil)
225
- end
226
- end
227
-
228
- test "keeps stats" do
229
- Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
230
- Resque::Job.create(:jobs, BadJob)
231
- Resque::Job.create(:jobs, GoodJob)
232
-
233
- Resque::Job.create(:others, GoodJob)
234
- Resque::Job.create(:others, GoodJob)
235
-
236
- stats = Resque.info
237
- assert_equal 8, stats[:pending]
238
-
239
- @worker = Resque::Worker.new(:jobs)
240
- @worker.register_worker
241
- 2.times { @worker.process }
242
-
243
- job = @worker.reserve
244
- @worker.working_on job
245
-
246
- stats = Resque.info
247
- assert_equal 1, stats[:working]
248
- assert_equal 1, stats[:workers]
249
-
250
- @worker.done_working
251
-
252
- stats = Resque.info
253
- assert_equal 3, stats[:queues]
254
- assert_equal 3, stats[:processed]
255
- assert_equal 1, stats[:failed]
256
- if ENV.key? 'RESQUE_DISTRIBUTED'
257
- assert_equal [Resque.redis.respond_to?(:server) ? 'localhost:9736, localhost:9737' : 'redis://localhost:9736/0, redis://localhost:9737/0'], stats[:servers]
258
- else
259
- assert_equal [Resque.redis.respond_to?(:server) ? 'localhost:9736' : 'redis://localhost:9736/0'], stats[:servers]
260
- end
261
- end
262
-
263
- test "decode bad json" do
264
- assert_raises Resque::Helpers::DecodeException do
265
- Resque.decode("{\"error\":\"Module not found \\u002\"}")
266
- end
267
- end
268
-
269
- test "inlining jobs" do
270
- begin
271
- Resque.inline = true
272
- Resque.enqueue(SomeIvarJob, 20, '/tmp')
273
- assert_equal 0, Resque.size(:ivar)
274
- ensure
275
- Resque.inline = false
276
- end
277
- end
278
- end