Skip to content

Commit

Permalink
Changed Worker.new to accept an options hash (with all values optiona…
Browse files Browse the repository at this point in the history
…l), or no args at all (to make everything default).
  • Loading branch information
pcantrell committed Mar 28, 2012
1 parent 1ac0d65 commit e1b791a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/queue_classic/worker.rb
@@ -1,7 +1,20 @@
module QC
class Worker

def initialize(q_name, top_bound, fork_worker, listening_worker, max_attempts)
def initialize(*args)
if args.length == 5
q_name, top_bound, fork_worker, listening_worker, max_attempts = *args
elsif args.length <= 1
opts = args.first || {}
q_name = opts[:q_name] || QC::QUEUE
top_bound = opts[:top_bound] || QC::TOP_BOUND
fork_worker = opts[:fork_worker] || QC::FORK_WORKER
listening_worker = opts[:listening_worker] || QC::LISTENING_WORKER
max_attempts = opts[:max_attempts] || QC::MAX_LOCK_ATTEMPTS
else
raise ArgumentError, 'wrong number of arguments (expected no args, an options hash, or 5 separate args)'
end

log("worker initialized")
@running = true

Expand Down

0 comments on commit e1b791a

Please sign in to comment.