Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
more robust middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
schasse committed Mar 10, 2015
1 parent 1aa93b0 commit 19b7842
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sidekiq-middleware/client/unique_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module Middleware
module Client
class UniqueJobs
def call(worker_class, item, queue, redis_pool = nil)
worker_class = worker_class.constantize if worker_class.is_a?(String)
enabled = Sidekiq::Middleware::Helpers.unique_enabled?(worker_class, item)
if Object.const_defined?(worker_class.to_s)
worker_class = worker_class.to_s.constantize
enabled = Sidekiq::Middleware::Helpers.unique_enabled?(worker_class, item)
end

if enabled
expiration = Sidekiq::Middleware::Helpers.unique_expiration(worker_class)
Expand Down
9 changes: 9 additions & 0 deletions test/test_unique_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,14 @@ def perform(id, unlock)
assert_equal 5, Sidekiq.redis { |c| c.zcard('schedule') }
end
end

describe 'when the Worker is not defined' do
it 'does not crash' do
Sidekiq::Client.push(
'queue' => 'default',
'class' => 'UndefinedWorker',
'args' => ['no_argument'])
end
end
end
end

0 comments on commit 19b7842

Please sign in to comment.