Sha256: 1f62e8613eee857cf9986016a1460584003f90c89316959facf19a03328eb7f5

Contents?: true

Size: 933 Bytes

Versions: 4

Compression:

Stored size: 933 Bytes

Contents

require 'beanstalk-client'

module Quebert
  module Backend
    
    # Manage jobs on a Beanstalk queue out of process
    class Beanstalk < Beanstalk::Pool
      def put(job, *args)
        super Job.to_json(job, *args)
      end
      
      def reserve_with_consumer
        Consumer::Beanstalk.new(reserve_without_consumer, self)
      end
      alias :reserve_without_consumer :reserve
      alias :reserve :reserve_with_consumer
      
      # For testing purposes... I think there's a better way to do this though.
      def drain!
        while peek_ready do
          reserve_without_consumer.delete
        end
        while job = peek_buried do
          last_conn.kick 1 # what? Why the 1? it kicks them all?
          reserve_without_consumer.delete
        end
      end
      
      def self.configure(opts={})
        opts[:host] ||= '127.0.0.1:11300'
        new(opts[:host], opts[:tube])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
quebert-0.0.4 lib/quebert/backend/beanstalk.rb
quebert-0.0.3 lib/quebert/backend/beanstalk.rb
quebert-0.0.1 lib/quebert/backend/beanstalk.rb
quebert-0.0.0 lib/quebert/backend/beanstalk.rb