Sha256: ca928e69fa34890188b8e37afa3efaeed6f5fd9dfbd6e1e5d41190135d367167
Contents?: true
Size: 981 Bytes
Versions: 2
Compression:
Stored size: 981 Bytes
Contents
$:.unshift ::File.dirname(__FILE__) + '/../lib' require 'rubygems' require 'raemon' require 'beanstalk-client' class JobWorker include Raemon::Worker def start logger.info "=> Starting worker #{Process.pid}" @beanstalk = Beanstalk::Pool.new(['localhost:11300']) end def stop logger.info "=> Stopping worker #{Process.pid}" @beanstalk.close exit end def execute loop do stop if shutting_down? begin job = @beanstalk.reserve(2) rescue Beanstalk::TimedOut end if job logger.info "(#{Process.ppid}:#{Process.pid}) got job: #{job.inspect}" # process job here ... job.delete end end end end ROOT_DIR = File.expand_path('~') # Raemon::Master.startup 3, JobWorker, { # :detach => true, # :logger => Logger.new("#{ROOT_DIR}/beanstalk.log"), # :pid_file => "#{ROOT_DIR}/beanstalk.pid" # } Raemon::Master.startup 3, JobWorker
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
raemon-0.1.2 | examples/beanstalk.rb |
raemon-0.1.1 | examples/beanstalk.rb |