Class: Beanstalk::Pool

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

Constant Summary

DONT_ADD =
Set['name', 'version', 'pid']

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Pool) initialize(addrs, default_tube = nil)



233
234
235
236
237
238
239
# File 'lib/beanstalk-client/connection.rb', line 233

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

- (Object) last_conn

Returns the value of attribute last_conn



231
232
233
# File 'lib/beanstalk-client/connection.rb', line 231

def last_conn
  @last_conn
end

Instance Method Details

- (Object) close



328
329
330
331
332
333
334
335
# File 'lib/beanstalk-client/connection.rb', line 328

def close
  while @connections.size > 0
    addr = @connections.keys.last
    conn = @connections[addr]
    @connections.delete(addr)
    conn.close
  end
end

- (Object) connect



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/beanstalk-client/connection.rb', line 241

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

- (Object) ignore(tube)



290
291
292
293
294
# File 'lib/beanstalk-client/connection.rb', line 290

def ignore(tube)
  r = send_to_all_conns(:ignore, tube)
  @watch_list = send_to_rand_conn(:list_tubes_watched, true)
  return r
end

- (Object) last_server



264
265
266
# File 'lib/beanstalk-client/connection.rb', line 264

def last_server
  @last_conn.addr
end

- (Object) list_tube_used



316
317
318
# File 'lib/beanstalk-client/connection.rb', line 316

def list_tube_used()
  send_to_all_conns(:list_tube_used)
end

- (Object) list_tubes



312
313
314
# File 'lib/beanstalk-client/connection.rb', line 312

def list_tubes()
  send_to_all_conns(:list_tubes)
end

- (Object) list_tubes_watched(*args)



320
321
322
# File 'lib/beanstalk-client/connection.rb', line 320

def list_tubes_watched(*args)
  send_to_all_conns(:list_tubes_watched, *args)
end

- (Object) open_connections



260
261
262
# File 'lib/beanstalk-client/connection.rb', line 260

def open_connections()
  @connections.values()
end

- (Object) peek_buried



345
346
347
# File 'lib/beanstalk-client/connection.rb', line 345

def peek_buried()
  send_to_each_conn_first_res(:peek_buried)
end

- (Object) peek_delayed



341
342
343
# File 'lib/beanstalk-client/connection.rb', line 341

def peek_delayed()
  send_to_each_conn_first_res(:peek_delayed)
end

- (Object) peek_job(id)



349
350
351
# File 'lib/beanstalk-client/connection.rb', line 349

def peek_job(id)
  make_hash(send_to_all_conns(:peek_job, id))
end

- (Object) peek_ready



337
338
339
# File 'lib/beanstalk-client/connection.rb', line 337

def peek_ready()
  send_to_each_conn_first_res(:peek_ready)
end

- (Object) put(body, pri = 65536, delay = 0, ttr = 120)



268
269
270
# File 'lib/beanstalk-client/connection.rb', line 268

def put(body, pri=65536, delay=0, ttr=120)
  send_to_rand_conn(:put, body, pri, delay, ttr)
end

- (Object) raw_stats



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

def raw_stats()
  send_to_all_conns(:stats)
end

- (Object) raw_stats_tube(tube)



304
305
306
# File 'lib/beanstalk-client/connection.rb', line 304

def raw_stats_tube(tube)
  send_to_all_conns(:stats_tube, tube)
end

- (Object) remove(conn)



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

def remove(conn)
  @connections.delete(conn.addr)
end

- (Object) reserve(timeout = nil)



276
277
278
# File 'lib/beanstalk-client/connection.rb', line 276

def reserve(timeout=nil)
  send_to_rand_conn(:reserve, timeout)
end

- (Object) stats



300
301
302
# File 'lib/beanstalk-client/connection.rb', line 300

def stats()
  sum_hashes(raw_stats.values)
end

- (Object) stats_tube(tube)



308
309
310
# File 'lib/beanstalk-client/connection.rb', line 308

def stats_tube(tube)
  sum_hashes(raw_stats_tube(tube).values)
end

- (Object) use(tube)



280
281
282
# File 'lib/beanstalk-client/connection.rb', line 280

def use(tube)
  send_to_all_conns(:use, tube)
end

- (Object) watch(tube)



284
285
286
287
288
# File 'lib/beanstalk-client/connection.rb', line 284

def watch(tube)
  r = send_to_all_conns(:watch, tube)
  @watch_list = send_to_rand_conn(:list_tubes_watched, true)
  return r
end

- (Object) yput(obj, pri = 65536, delay = 0, ttr = 120)



272
273
274
# File 'lib/beanstalk-client/connection.rb', line 272

def yput(obj, pri=65536, delay=0, ttr=120)
  send_to_rand_conn(:yput, obj, pri, delay, ttr)
end