Class: W3map::DistributedQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/w3map.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


86
87
88
# File 'lib/w3map.rb', line 86

def already_processed?(url)
  @redis.sismember urls_schema, url
end

#closeObject



76
77
78
# File 'lib/w3map.rb', line 76

def close
  @redis.quit
end

#flush_processing_urlsObject



96
97
98
# File 'lib/w3map.rb', line 96

def flush_processing_urls
  @redis.del urls_schema
end

#flush_queueObject



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

#lenObject



83
84
85
# File 'lib/w3map.rb', line 83

def len
  @redis.llen queue_schema
end

#popObject



92
93
94
95
# File 'lib/w3map.rb', line 92

def pop
  _, url = @redis.brpop queue_schema
  url
end

#processing_urlsObject



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