Class: SourceMonitor::Scraping::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/source_monitor/scraping/runner.rb

Overview

Orchestrates a single item scrape: pre-flight checks (scraping enabled?), state management (mark_processing!, mark_failed!, clear_inflight!), and delegation to ItemScraper. Extracted from ScrapeItemJob so scraping logic can be invoked synchronously.

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Runner

Returns a new instance of Runner.



10
11
12
13
# File 'lib/source_monitor/scraping/runner.rb', line 10

def initialize(item)
  @item = item
  @source = item.source
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/source_monitor/scraping/runner.rb', line 15

def call
  unless source&.scraping_enabled?
    log("runner:skipped_scraping_disabled")
    State.clear_inflight!(item)
    return
  end

  State.mark_processing!(item)
  SourceMonitor::Scraping::ItemScraper.new(item: item, source: source).call
  log("runner:completed", status: item.scrape_status)
rescue StandardError => error
  log("runner:error", error: error.message)
  State.mark_failed!(item)
  raise
ensure
  State.clear_inflight!(item) if item
end