Class: Ayl::Beanstalk::Engine

Inherits:
Object
  • Object
show all
Includes:
Pool, Logging
Defined in:
lib/ayl-beanstalk/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pool

#pool

Constructor Details

#initialize(host = 'localhost', port = 11300) ⇒ Engine

Returns a new instance of Engine.



11
12
13
14
15
# File 'lib/ayl-beanstalk/engine.rb', line 11

def initialize(host='localhost', port=11300)
  logger.debug "#{self.class.name}.initialize(#{host.inspect}, #{port})"
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/ayl-beanstalk/engine.rb', line 9

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/ayl-beanstalk/engine.rb', line 9

def port
  @port
end

Instance Method Details

#asynchronous?Boolean

Returns:

  • (Boolean)


17
# File 'lib/ayl-beanstalk/engine.rb', line 17

def asynchronous?() true end

#is_connected?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
# File 'lib/ayl-beanstalk/engine.rb', line 19

def is_connected?
  connected = true
  begin
    pool
  rescue ::Beanstalk::NotConnected => ex
    logger.error "#{self.class.name} not connected error: #{ex}"
    connected = false
  end
  connected
end

#submit(message) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ayl-beanstalk/engine.rb', line 30

def submit(message)
  log_call(:submit) do
    begin
      pool.use(message.options.queue_name)
      code = message.to_rrepr
      logger.info "#{self.class.name} submitting '#{code}' to tube '#{message.options.queue_name}'"
      pool.yput(message.to_hash, message.options.priority, message.options.delay, message.options.time_to_run)
    rescue Exception => ex
      logger.error "Error submitting message to beanstalk: #{ex}"
    end
  end
end

#workerObject



43
44
45
# File 'lib/ayl-beanstalk/engine.rb', line 43

def worker
  Ayl::Beanstalk::Worker.new(@host, @port)
end