Class: Kudzu::Adapter::ActiveRecord::Frontier
- Inherits:
-
Object
- Object
- Kudzu::Adapter::ActiveRecord::Frontier
- Defined in:
- lib/kudzu/adapter/active_record/frontier.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #dequeue(limit: 1) ⇒ Object
- #enqueue(links, depth: 0) ⇒ Object
-
#initialize(uuid, config = {}) ⇒ Frontier
constructor
A new instance of Frontier.
Constructor Details
#initialize(uuid, config = {}) ⇒ Frontier
7 8 9 10 |
# File 'lib/kudzu/adapter/active_record/frontier.rb', line 7 def initialize(uuid, config = {}) @uuid = uuid @monitor = Monitor.new end |
Instance Method Details
#clear ⇒ Object
31 32 33 |
# File 'lib/kudzu/adapter/active_record/frontier.rb', line 31 def clear Link.where(uuid: @uuid).delete_all end |
#dequeue(limit: 1) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kudzu/adapter/active_record/frontier.rb', line 20 def dequeue(limit: 1) @monitor.synchronize do links = Link.where(uuid: @uuid, state: 0).order(id: :asc).limit(limit).to_a links.each do |link| link.state = 1 link.save end links end end |
#enqueue(links, depth: 0) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/kudzu/adapter/active_record/frontier.rb', line 12 def enqueue(links, depth: 0) @monitor.synchronize do links = filter_existing_urls(links) Link.bulk_import(links) links end end |