Class: Beanstalk::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/beanstalk-client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_connObject

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

#closeObject



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

#connectObject



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_serverObject



244
245
246
# File 'lib/beanstalk-client/connection.rb', line 244

def last_server
  @last_conn.addr
end

#list_tube_usedObject



296
297
298
# File 'lib/beanstalk-client/connection.rb', line 296

def list_tube_used()
  send_to_all_conns(:list_tube_used)
end

#list_tubesObject



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_connectionsObject



240
241
242
# File 'lib/beanstalk-client/connection.rb', line 240

def open_connections()
  @connections.values()
end

#peek_buriedObject



325
326
327
# File 'lib/beanstalk-client/connection.rb', line 325

def peek_buried()
  send_to_each_conn_first_res(:peek_buried)
end

#peek_delayedObject



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_readyObject



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_statsObject



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

#reserveObject



256
257
258
# File 'lib/beanstalk-client/connection.rb', line 256

def reserve()
  send_to_rand_conn(:reserve)
end

#statsObject



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