Skip to content

Commit

Permalink
Merge pull request #29 from nonsensery/raise-when-removing-fails
Browse files Browse the repository at this point in the history
Raise exception when removing fails
  • Loading branch information
drfeelngood committed Jun 22, 2015
2 parents 3972241 + e707202 commit 8c54262
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/resque/plugins/batched_job.rb
Expand Up @@ -83,7 +83,10 @@ def batch_exist?(id)
# @param id (see Resque::Plugins::BatchedJob#after_enqueue_batch)
def remove_batched_job(id, *args)
mutex(id) do |bid|
redis.lrem(bid, 1, Resque.encode(:class => self.name, :args => args))
removed_count = redis.lrem(bid, 1, Resque.encode(:class => self.name, :args => args))

raise "Failed to remove batched job, id: #{id}, args: #{args.join(', ')}" if removed_count != 1

redis.llen(bid)
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_batched_job.rb
Expand Up @@ -152,6 +152,18 @@ def test_remove_batched_job
assert($batch_complete)
assert(Job.batch_complete?(@batch_id))
assert_equal(false, Job.batch_exist?(@batch_id))

assert_raise RuntimeError do
Job.remove_batched_job(@batch_id, "foo")
end
end

def test_mutating_job
Resque.enqueue_batched_job(MutatingJob, @batch_id, { 'ok' => 'so far, so good' })

assert_raise RuntimeError do
Resque.reserve(:test).perform
end
end

def test_enqueue_batched_job
Expand Down
16 changes: 15 additions & 1 deletion test/test_helper.rb
Expand Up @@ -31,4 +31,18 @@ def self.after_batch_hook(id)
$batch_complete = true
end

end
end

class MutatingJob
extend Resque::Plugins::BatchedJob
@queue = :test

def self.perform(batch_id, arg)
arg['oops'] = 'mutated!!'
end

def self.after_batch_hook(batch_id, arg)
$batch_complete = true
end

end

0 comments on commit 8c54262

Please sign in to comment.