Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix silent exceptions when lock timeout expires before exception raised. #25

Merged
merged 1 commit into from Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/resque/plugins/lock_timeout.rb
Expand Up @@ -287,15 +287,13 @@ def around_perform_lock(*args)
ensure
# Release the lock on success and error. Unless a lock_timeout is
# used, then we need to be more careful before releasing the lock.
unless lock_until === true
now = Time.now.to_i
if lock_until < now
# Eeek! Lock expired before perform finished. Trigger callback.
lock_expired_before_release(*args)
return # dont relase lock.
end
now = Time.now.to_i
if lock_until != true and lock_until < now
# Eeek! Lock expired before perform finished. Trigger callback.
lock_expired_before_release(*args)
else
release_lock!(*args)
end
release_lock!(*args)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/lock_test.rb
Expand Up @@ -225,4 +225,10 @@ def test_loner_job_should_get_enqueued_if_previous_inline_job_finished
Resque.enqueue(LonelyJob)
assert_equal 1, Resque.size(:test), "Should have enqueued the job"
end

def test_exceptions_in_job_after_timeout_should_be_marked_as_failure
Resque.enqueue(FailingAfterTimeoutJob)
@worker.process
assert_equal 1, Resque::Failure.count, "Should have been marked as failure"
end
end
12 changes: 12 additions & 0 deletions test/test_jobs.rb
Expand Up @@ -158,3 +158,15 @@ def self.perform
sleep 2
end
end

# Job that raises an error after its timeout.
class FailingAfterTimeoutJob
extend Resque::Plugins::LockTimeout
@queue = :test
@lock_timeout = 1

def self.perform
sleep 2
raise
end
end