Method: Chapman::Worker#prep

Defined in:
lib/chapman/worker.rb

#prep(jobs = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chapman/worker.rb', line 19

def prep(jobs=nil)
  raise Chapman::Exceptions::NoJobsDefined unless defined?(@handlers)
  @error_handler = nil unless defined?(@error_handler)

  jobs ||= all_jobs

  jobs.each do |job|
    raise(Chapman::Exceptions::NoSuchJob, job) unless @handlers[job]
  end

  log "Working #{jobs.size} jobs: [ #{jobs.join(' ')} ]"

  jobs.each { |job| beanstalk.watch(job) }

  beanstalk.list_tubes_watched.each do |server, tubes|
    tubes.each { |tube| beanstalk.ignore(tube) unless jobs.include?(tube) }
  end
rescue Beanstalk::NotConnected => e
  failed_connection(e)
end