Skip to content

Commit

Permalink
fix: unlock unique jobs without args
Browse files Browse the repository at this point in the history
  • Loading branch information
spyderdfx committed Nov 27, 2023
1 parent 2adb68d commit 2380cf0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in resque-integration.gemspec
gemspec

gem 'loofah', '< 2.20.0', require: false
gem 'pry', '< 0.13.0', require: false
2 changes: 1 addition & 1 deletion lib/resque/integration/unique.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def around_perform_lock(_meta_id, *args)

# When job is dequeued we should remove lock
def after_dequeue_lock(_meta_id, *args)
unlock(*args) unless args.empty?
unlock(*args)
end

# Fail metadata if dequeue succeed
Expand Down
36 changes: 32 additions & 4 deletions spec/resque/integration/unique_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class JobDequeueTest

@queue = :queue2

def self.execute(x)
def self.execute(*params)
sleep 0.1
end
end
Expand All @@ -105,14 +105,24 @@ def self.execute(x)
meta.should be_failed
end

it 'dequeues and unlocks job without args if job is not in work now' do
JobDequeueTest.enqueue
JobDequeueTest.should be_enqueued

JobDequeueTest.dequeue
JobDequeueTest.should_not be_enqueued
JobDequeueTest.should_not be_locked

meta = JobDequeueTest.get_meta(JobDequeueTest.meta_id)
meta.should be_failed
end

it 'does not dequeue jobs in progress' do
meta = JobDequeueTest.enqueue(1)

job = Resque.reserve(:queue2)

worker = Thread.new {
job.perform
}
worker = Thread.new { job.perform }

sleep 0.01 # give a worker some time to start
meta.reload!
Expand All @@ -124,6 +134,24 @@ def self.execute(x)

worker.join
end

it 'does not dequeue jobs without args in progress' do
meta = JobDequeueTest.enqueue

job = Resque.reserve(:queue2)

worker = Thread.new { job.perform }

sleep 0.01 # give a worker some time to start
meta.reload!
meta.should be_working

JobDequeueTest.dequeue
JobDequeueTest.should be_locked
JobDequeueTest.should be_enqueued

worker.join
end
end

describe Resque::Integration::Unique, '#on_failure_retry' do
Expand Down

0 comments on commit 2380cf0

Please sign in to comment.