Class: SuperPoller::StarlingQueue
- Inherits:
-
Object
- Object
- SuperPoller::StarlingQueue
- Defined in:
- lib/super_poller/starling_queue.rb
Instance Method Summary collapse
- #any? ⇒ Boolean
- #coerce(message) ⇒ Object
- #empty? ⇒ Boolean
- #fetch ⇒ Object
- #fix_encoding(v) ⇒ Object
- #flush ⇒ Object
-
#initialize(queue_name, *args) ⇒ StarlingQueue
constructor
A new instance of StarlingQueue.
- #length ⇒ Object
- #pop ⇒ Object
- #push(v, raw = false) ⇒ Object
Constructor Details
#initialize(queue_name, *args) ⇒ StarlingQueue
Returns a new instance of StarlingQueue.
5 6 7 8 |
# File 'lib/super_poller/starling_queue.rb', line 5 def initialize(queue_name, *args) @queue_name = queue_name.to_s @queue = Starling.new(*args) end |
Instance Method Details
#any? ⇒ Boolean
30 31 32 |
# File 'lib/super_poller/starling_queue.rb', line 30 def any? !empty? end |
#coerce(message) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/super_poller/starling_queue.rb', line 55 def coerce() unless .start_with?('{') = MultiJson.dump(Marshal.load()) end = fix_encoding() MultiJson.decode() end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/super_poller/starling_queue.rb', line 26 def empty? length.zero? end |
#fetch ⇒ Object
18 19 20 |
# File 'lib/super_poller/starling_queue.rb', line 18 def fetch coerce @queue.fetch(@queue_name, true) end |
#fix_encoding(v) ⇒ Object
46 47 48 |
# File 'lib/super_poller/starling_queue.rb', line 46 def fix_encoding(v) v.force_encoding('UTF-8') end |
#flush ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/super_poller/starling_queue.rb', line 34 def flush @queue.delete(@queue_name) rescue MemCache::MemCacheError => e if e. =~ /bad command line format/ STDERR.puts "WARNING: Server could not handle delete command. Falling back to the MUCH slower, and quite unreliable flush method. Consider using Reevoo Starling (http://github.com/reevoo/starling)" @queue.flush(@queue_name) else raise end end |
#length ⇒ Object
22 23 24 |
# File 'lib/super_poller/starling_queue.rb', line 22 def length @queue.sizeof(@queue_name) end |
#pop ⇒ Object
10 11 12 |
# File 'lib/super_poller/starling_queue.rb', line 10 def pop coerce @queue.get(@queue_name, true) end |
#push(v, raw = false) ⇒ Object
14 15 16 |
# File 'lib/super_poller/starling_queue.rb', line 14 def push(v, raw = false) @queue.set(@queue_name, v, 0, raw) end |