Skip to content

Commit 3b3281f

Browse files
committed
Don't use deprecated Redis methods (incr => incrby, flush_all => flushall)
1 parent e0be8b2 commit 3b3281f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

lib/resque/stat.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def [](stat)
2424
# Can optionally accept a second int parameter. The stat is then
2525
# incremented by that amount.
2626
def incr(stat, by = 1)
27-
redis.incr("stat:#{stat}", by)
27+
redis.incrby("stat:#{stat}", by)
2828
end
2929

3030
# Increments a stat by one.
@@ -37,7 +37,7 @@ def <<(stat)
3737
# Can optionally accept a second int parameter. The stat is then
3838
# decremented by that amount.
3939
def decr(stat, by = 1)
40-
redis.decr("stat:#{stat}", by)
40+
redis.decrby("stat:#{stat}", by)
4141
end
4242

4343
# Decrements a stat by one.

lib/resque/worker.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ def run_hook(name, *args)
328328
def unregister_worker
329329
# If we're still processing a job, make sure it gets logged as a
330330
# failure.
331-
if job
331+
if (hash = processing) && !hash.empty?
332+
job = Job.new(hash['queue'], hash['payload'])
332333
# Ensure the proper worker is attached to this job, even if
333334
# it's not the precise instance that died.
334335
job.worker = self

test/resque_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
context "Resque" do
44
setup do
5-
Resque.redis.flush_all
5+
Resque.redis.flushall
66

77
Resque.push(:people, { 'name' => 'chris' })
88
Resque.push(:people, { 'name' => 'bob' })
@@ -166,7 +166,7 @@
166166
end
167167

168168
test "queues are always a list" do
169-
Resque.redis.flush_all
169+
Resque.redis.flushall
170170
assert_equal [], Resque.queues
171171
end
172172

@@ -217,7 +217,7 @@
217217
assert_equal 1, stats[:failed]
218218
assert_equal ['localhost:9736'], stats[:servers]
219219
end
220-
220+
221221
test "decode bad json" do
222222
assert_nil Resque.decode("{\"error\":\"Module not found \\u002\"}")
223223
end

test/worker_test.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
context "Resque::Worker" do
44
setup do
5-
Resque.redis.flush_all
5+
Resque.redis.flushall
66

77
Resque.before_first_fork = nil
88
Resque.before_fork = nil
@@ -18,13 +18,20 @@
1818
assert_equal 1, Resque::Failure.count
1919
end
2020

21-
test "failed jobs report excpetion and message" do
21+
test "failed jobs report exception and message" do
2222
Resque::Job.create(:jobs, BadJobWithSyntaxError)
2323
@worker.work(0)
2424
assert_equal('SyntaxError', Resque::Failure.all['exception'])
2525
assert_equal('Extra Bad job!', Resque::Failure.all['error'])
2626
end
2727

28+
test "fails uncompleted jobs on exit" do
29+
job = Resque::Job.new(:jobs, [GoodJob, "blah"])
30+
@worker.working_on(job)
31+
@worker.unregister_worker
32+
assert_equal 1, Resque::Failure.count
33+
end
34+
2835
test "can peek at failed jobs" do
2936
10.times { Resque::Job.create(:jobs, BadJob) }
3037
@worker.work(0)
@@ -253,7 +260,7 @@
253260
end
254261

255262
test "Will call a before_first_fork hook only once" do
256-
Resque.redis.flush_all
263+
Resque.redis.flushall
257264
$BEFORE_FORK_CALLED = 0
258265
Resque.before_first_fork = Proc.new { $BEFORE_FORK_CALLED += 1 }
259266
workerA = Resque::Worker.new(:jobs)
@@ -270,7 +277,7 @@
270277
end
271278

272279
test "Will call a before_fork hook before forking" do
273-
Resque.redis.flush_all
280+
Resque.redis.flushall
274281
$BEFORE_FORK_CALLED = false
275282
Resque.before_fork = Proc.new { $BEFORE_FORK_CALLED = true }
276283
workerA = Resque::Worker.new(:jobs)
@@ -282,7 +289,7 @@
282289
end
283290

284291
test "Will call an after_fork hook after forking" do
285-
Resque.redis.flush_all
292+
Resque.redis.flushall
286293
$AFTER_FORK_CALLED = false
287294
Resque.after_fork = Proc.new { $AFTER_FORK_CALLED = true }
288295
workerA = Resque::Worker.new(:jobs)

0 commit comments

Comments
 (0)