class Backburner::Workers::Forking

Public Instance Methods

coolest_exit() click to toggle source

Exit with Kernel.exit! to avoid at_exit callbacks that should belongs to parent process We will use exitcode 99 that means the fork reached the garbage number

# File lib/backburner/workers/forking.rb, line 46
def coolest_exit
  Kernel.exit! 99
end
fork_one_job() click to toggle source

Need to re-establish the connection to the server(s) after forking Waits for a job, works the job, and exits

# File lib/backburner/workers/forking.rb, line 30
def fork_one_job
  pid = Process.fork do
    work_one_job
    coolest_exit
  end
  Process.wait(pid)
end
on_reconnect(conn) click to toggle source
# File lib/backburner/workers/forking.rb, line 38
def on_reconnect(conn)
  @connection = conn
  prepare
end
prepare() click to toggle source

Used to prepare job queues before processing jobs. Setup beanstalk tube_names and watch all specified tubes for jobs.

@raise [Beaneater::NotConnected] If beanstalk fails to connect. @example

@worker.prepare
# File lib/backburner/workers/forking.rb, line 11
def prepare
  self.tube_names.map! { |name| expand_tube_name(name)  }.uniq!
  log_info "Working #{tube_names.size} queues: [ #{tube_names.join(', ')} ]"
  self.connection.tubes.watch!(*self.tube_names)
end
start() click to toggle source

Starts processing new jobs indefinitely. Primary way to consume and process jobs in specified tubes.

@example

@worker.start
# File lib/backburner/workers/forking.rb, line 23
def start
  prepare
  loop { fork_one_job }
end