Class: W3map::DistributedQueue
- Inherits:
-
Object
- Object
- W3map::DistributedQueue
- Defined in:
- lib/w3map.rb
Instance Method Summary collapse
- #add_to_processing_urls(url) ⇒ Object
- #already_processed?(url) ⇒ Boolean
- #close ⇒ Object
- #flush_processing_urls ⇒ Object
- #flush_queue ⇒ Object
-
#initialize(session_name, config = {}) ⇒ DistributedQueue
constructor
A new instance of DistributedQueue.
- #last_entries(limit) ⇒ Object
- #len ⇒ Object
- #pop ⇒ Object
- #processing_urls ⇒ Object
- #push(url) ⇒ Object
Constructor Details
#initialize(session_name, config = {}) ⇒ DistributedQueue
Returns a new instance of DistributedQueue.
65 66 67 68 |
# File 'lib/w3map.rb', line 65 def initialize(session_name, config={}) @session_name = session_name @redis = Redis.new config end |
Instance Method Details
#add_to_processing_urls(url) ⇒ Object
73 74 75 |
# File 'lib/w3map.rb', line 73 def add_to_processing_urls(url) @redis.sadd urls_schema, url end |
#already_processed?(url) ⇒ Boolean
86 87 88 |
# File 'lib/w3map.rb', line 86 def already_processed?(url) @redis.sismember urls_schema, url end |
#close ⇒ Object
76 77 78 |
# File 'lib/w3map.rb', line 76 def close @redis.quit end |
#flush_processing_urls ⇒ Object
96 97 98 |
# File 'lib/w3map.rb', line 96 def flush_processing_urls @redis.del urls_schema end |
#flush_queue ⇒ Object
99 100 101 |
# File 'lib/w3map.rb', line 99 def flush_queue @redis.del queue_schema end |
#last_entries(limit) ⇒ Object
79 80 81 82 |
# File 'lib/w3map.rb', line 79 def last_entries(limit) limit = limit + -1 if limit > 0 @redis.lrange queue_schema, 0, limit end |
#len ⇒ Object
83 84 85 |
# File 'lib/w3map.rb', line 83 def len @redis.llen queue_schema end |
#pop ⇒ Object
92 93 94 95 |
# File 'lib/w3map.rb', line 92 def pop _, url = @redis.brpop queue_schema url end |
#processing_urls ⇒ Object
89 90 91 |
# File 'lib/w3map.rb', line 89 def processing_urls @redis.smembers(urls_schema) end |
#push(url) ⇒ Object
69 70 71 72 |
# File 'lib/w3map.rb', line 69 def push(url) add_to_processing_urls url @redis.lpush queue_schema, url end |