class Swarm::Beanstalk::Queue
Attributes
address[R]
tube[R]
worker[R]
Public Class Methods
new(name:, address: "localhost:11300", worker: nil)
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 9 def initialize(name:, address: "localhost:11300", worker: nil) @name = name @address = address @beaneater = Beaneater.new(@address) @tube = @beaneater.tubes[@name] @worker = worker end
Public Instance Methods
add_job(data)
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 21 def add_job(data) Job.new(tube.put(data.to_json)) end
clear()
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 35 def clear tube.clear end
idle?()
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 39 def idle? tube.peek(:ready).nil? end
prepare_for_work(worker)
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 17 def prepare_for_work(worker) self.class.new(:name => name, :address => address, worker: worker) end
reserve_job(worker)
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 25 def reserve_job(worker) Job.new(tube.reserve) rescue Beaneater::NotFoundError, Beaneater::TimedOutError, Beaneater::JobNotReserved raise JobReservationFailed end
worker_count()
click to toggle source
# File lib/swarm/beanstalk/queue.rb, line 31 def worker_count tube.stats.current_watching end