Class: Airbrush::Listeners::Memcache

Inherits:
Listener show all
Defined in:
lib/airbrush/listeners/memcache.rb

Constant Summary collapse

DEFAULT_POLL_FREQUENCY =

seconds

2
DEFAULT_INCOMING_QUEUE =
'airbrush_incoming_queue'

Instance Attribute Summary collapse

Attributes inherited from Listener

#handler

Instance Method Summary collapse

Constructor Details

#initialize(host, frequency = DEFAULT_POLL_FREQUENCY) ⇒ Memcache

Returns a new instance of Memcache.



11
12
13
14
15
# File 'lib/airbrush/listeners/memcache.rb', line 11

def initialize(host, frequency = DEFAULT_POLL_FREQUENCY)
  @host = host
  @poll_frequency = frequency
  catch_signals(:int)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/airbrush/listeners/memcache.rb', line 9

def host
  @host
end

#poll_frequencyObject (readonly)

Returns the value of attribute poll_frequency.



9
10
11
# File 'lib/airbrush/listeners/memcache.rb', line 9

def poll_frequency
  @poll_frequency
end

Instance Method Details

#startObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/airbrush/listeners/memcache.rb', line 17

def start
  @running = true
  @starling = MemCache.new(@host)

  log.debug 'Accepting incoming jobs'

  loop do
    poll do |operation|
      process operation
    end

    break unless @running
    sleep @poll_frequency
  end

  @starling.reset
end