Class: Workling::Clients::MemcacheQueueClient

Inherits:
Base
  • Object
show all
Defined in:
lib/workling/clients/memcache_queue_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#subscribe

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)

delegates directly through to the memcache connection.



73
74
75
76
77
78
79
# File 'lib/workling/clients/memcache_queue_client.rb', line 73

def method_missing(method, *args)
  begin
    self.connection.send(method, *args)
  rescue MemCache::MemCacheError => e
    raise Workling::WorklingConnectionError.new("#{e.class.to_s} - #{e.message}")        
  end
end

Instance Attribute Details

#connectionObject

the memcache connection object



24
25
26
# File 'lib/workling/clients/memcache_queue_client.rb', line 24

def connection
  @connection
end

#queueserver_urlsObject

the url with which the memcache client expects to reach starling



21
22
23
# File 'lib/workling/clients/memcache_queue_client.rb', line 21

def queueserver_urls
  @queueserver_urls
end

Instance Method Details

#closeObject

closes the memcache connection



43
44
45
46
# File 'lib/workling/clients/memcache_queue_client.rb', line 43

def close
  self.connection.flush_all
  self.connection.reset
end

#connectObject

the client attempts to connect to queueserver using the configuration options found in

    Workling.config. this can be configured in config/workling.yml. 

the initialization code will raise an exception if memcache-client cannot connect 
to queueserver.


34
35
36
37
38
39
40
# File 'lib/workling/clients/memcache_queue_client.rb', line 34

def connect
  @queueserver_urls = Workling.config[:listens_on].split(',').map { |url| url ? url.strip : url }
  options = [@queueserver_urls, Workling.config[:memcache_options]].compact
  self.connection = MemcacheQueueClient.memcache_client_class.new(*options)
  
  raise_unless_connected!
end

#request(key, value) ⇒ Object

implements the client job request and retrieval



49
50
51
# File 'lib/workling/clients/memcache_queue_client.rb', line 49

def request(key, value)
  set(key, value)
end

#retrieve(key) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/workling/clients/memcache_queue_client.rb', line 53

def retrieve(key)
  begin
    get(key)
  rescue MemCache::MemCacheError => e
    # failed to enqueue, raise a workling error so that it propagates upwards
    raise Workling::WorklingError.new("#{e.class.to_s} - #{e.message}")        
  end
end