Class: Beanstalk::Pool
- Inherits:
-
Object
- Object
- Beanstalk::Pool
- Defined in:
- lib/beanstalk-client/connection.rb
Instance Attribute Summary collapse
-
#last_conn ⇒ Object
Returns the value of attribute last_conn.
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #ignore(tube) ⇒ Object
-
#initialize(addrs, default_tube = nil) ⇒ Pool
constructor
A new instance of Pool.
- #last_server ⇒ Object
- #list_tube_used ⇒ Object
- #list_tubes ⇒ Object
- #list_tubes_watched(*args) ⇒ Object
- #open_connections ⇒ Object
- #peek_buried ⇒ Object
- #peek_delayed ⇒ Object
- #peek_job(id) ⇒ Object
- #peek_ready ⇒ Object
- #put(body, pri = 65536, delay = 0, ttr = 120) ⇒ Object
- #raw_stats ⇒ Object
- #raw_stats_tube(tube) ⇒ Object
- #remove(conn) ⇒ Object
- #reserve ⇒ Object
- #stats ⇒ Object
- #stats_tube(tube) ⇒ Object
- #use(tube) ⇒ Object
- #watch(tube) ⇒ Object
- #yput(obj, pri = 65536, delay = 0, ttr = 120) ⇒ Object
Constructor Details
#initialize(addrs, default_tube = nil) ⇒ Pool
Returns a new instance of Pool.
213 214 215 216 217 218 219 |
# File 'lib/beanstalk-client/connection.rb', line 213 def initialize(addrs, default_tube=nil) @addrs = addrs @watch_list = ['default'] @default_tube=default_tube @watch_list = [default_tube] if default_tube connect() end |
Instance Attribute Details
#last_conn ⇒ Object
Returns the value of attribute last_conn.
211 212 213 |
# File 'lib/beanstalk-client/connection.rb', line 211 def last_conn @last_conn end |
Instance Method Details
#close ⇒ Object
308 309 310 311 312 313 314 315 |
# File 'lib/beanstalk-client/connection.rb', line 308 def close while @connections.size > 0 addr = @connections.keys.last conn = @connections[addr] @connections.delete(addr) conn.close end end |
#connect ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/beanstalk-client/connection.rb', line 221 def connect() @connections ||= {} @addrs.each do |addr| begin if !@connections.include?(addr) @connections[addr] = Connection.new(addr, @default_tube) prev_watched = @connections[addr].list_tubes_watched() to_ignore = prev_watched - @watch_list @watch_list.each{|tube| @connections[addr].watch(tube)} to_ignore.each{|tube| @connections[addr].ignore(tube)} end rescue Exception => ex puts "#{ex.class}: #{ex}" #puts begin ex.fixed_backtrace rescue ex.backtrace end end end @connections.size end |
#ignore(tube) ⇒ Object
270 271 272 273 274 |
# File 'lib/beanstalk-client/connection.rb', line 270 def ignore(tube) r = send_to_all_conns(:ignore, tube) @watch_list = send_to_rand_conn(:list_tubes_watched, true) return r end |
#last_server ⇒ Object
244 245 246 |
# File 'lib/beanstalk-client/connection.rb', line 244 def last_server @last_conn.addr end |
#list_tube_used ⇒ Object
296 297 298 |
# File 'lib/beanstalk-client/connection.rb', line 296 def list_tube_used() send_to_all_conns(:list_tube_used) end |
#list_tubes ⇒ Object
292 293 294 |
# File 'lib/beanstalk-client/connection.rb', line 292 def list_tubes() send_to_all_conns(:list_tubes) end |
#list_tubes_watched(*args) ⇒ Object
300 301 302 |
# File 'lib/beanstalk-client/connection.rb', line 300 def list_tubes_watched(*args) send_to_all_conns(:list_tubes_watched, *args) end |
#open_connections ⇒ Object
240 241 242 |
# File 'lib/beanstalk-client/connection.rb', line 240 def open_connections() @connections.values() end |
#peek_buried ⇒ Object
325 326 327 |
# File 'lib/beanstalk-client/connection.rb', line 325 def peek_buried() send_to_each_conn_first_res(:peek_buried) end |
#peek_delayed ⇒ Object
321 322 323 |
# File 'lib/beanstalk-client/connection.rb', line 321 def peek_delayed() send_to_each_conn_first_res(:peek_delayed) end |
#peek_job(id) ⇒ Object
329 330 331 |
# File 'lib/beanstalk-client/connection.rb', line 329 def peek_job(id) make_hash(send_to_all_conns(:peek_job, id)) end |
#peek_ready ⇒ Object
317 318 319 |
# File 'lib/beanstalk-client/connection.rb', line 317 def peek_ready() send_to_each_conn_first_res(:peek_ready) end |
#put(body, pri = 65536, delay = 0, ttr = 120) ⇒ Object
248 249 250 |
# File 'lib/beanstalk-client/connection.rb', line 248 def put(body, pri=65536, delay=0, ttr=120) send_to_rand_conn(:put, body, pri, delay, ttr) end |
#raw_stats ⇒ Object
276 277 278 |
# File 'lib/beanstalk-client/connection.rb', line 276 def raw_stats() send_to_all_conns(:stats) end |
#raw_stats_tube(tube) ⇒ Object
284 285 286 |
# File 'lib/beanstalk-client/connection.rb', line 284 def raw_stats_tube(tube) send_to_all_conns(:stats_tube, tube) end |
#remove(conn) ⇒ Object
304 305 306 |
# File 'lib/beanstalk-client/connection.rb', line 304 def remove(conn) @connections.delete(conn.addr) end |
#reserve ⇒ Object
256 257 258 |
# File 'lib/beanstalk-client/connection.rb', line 256 def reserve() send_to_rand_conn(:reserve) end |
#stats ⇒ Object
280 281 282 |
# File 'lib/beanstalk-client/connection.rb', line 280 def stats() sum_hashes(raw_stats.values) end |
#stats_tube(tube) ⇒ Object
288 289 290 |
# File 'lib/beanstalk-client/connection.rb', line 288 def stats_tube(tube) sum_hashes(raw_stats_tube(tube).values) end |
#use(tube) ⇒ Object
260 261 262 |
# File 'lib/beanstalk-client/connection.rb', line 260 def use(tube) send_to_all_conns(:use, tube) end |
#watch(tube) ⇒ Object
264 265 266 267 268 |
# File 'lib/beanstalk-client/connection.rb', line 264 def watch(tube) r = send_to_all_conns(:watch, tube) @watch_list = send_to_rand_conn(:list_tubes_watched, true) return r end |
#yput(obj, pri = 65536, delay = 0, ttr = 120) ⇒ Object
252 253 254 |
# File 'lib/beanstalk-client/connection.rb', line 252 def yput(obj, pri=65536, delay=0, ttr=120) send_to_rand_conn(:yput, obj, pri, delay, ttr) end |