Class: CrawlStation::ScheduleAdapters::DbAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/crawl_station/schedule_adapters/db_adapter.rb

Instance Method Summary collapse

Instance Method Details

#done(item) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/crawl_station/schedule_adapters/db_adapter.rb', line 31

def done(item)
  return if item.nil?
  schedule.transaction do
    model = schedule.find_by(id: item.id)
    model.done! if item.present?
  end
end

#empty?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/crawl_station/schedule_adapters/db_adapter.rb', line 19

def empty?
  schedule.waitings.size.zero?
end

#failed(item) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/crawl_station/schedule_adapters/db_adapter.rb', line 23

def failed(item)
  return if item.nil?
  schedule.transaction do
    model = schedule.find_by(id: item.id)
    model.failed! if item.present?
  end
end

#popObject



12
13
14
15
16
17
18
# File 'lib/crawl_station/schedule_adapters/db_adapter.rb', line 12

def pop
  schedule.transaction do
    model = schedule.waitings.first
    model.progressing!
    model
  end
end

#push(item) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/crawl_station/schedule_adapters/db_adapter.rb', line 4

def push(item)
  item = ParseStruct.new(item) if item.is_a?(Hash)
  schedule.new(
    parser: item.parser,
    namespace: item.namespace,
    link: item.link
  ).save
end