Module: Html2rss::Doctor::Botasaurus
- Defined in:
- lib/html2rss/doctor/botasaurus.rb
Overview
Preflight checks for Botasaurus scrape-api connectivity.
Defined Under Namespace
Class Method Summary collapse
- .call(sample_url: nil) ⇒ Result
- .env_check ⇒ Hash{Symbol => Object}
- .health_check(base_url) ⇒ Hash{Symbol => Object}
- .sample_scrape(url) ⇒ Hash{Symbol => Object}
Class Method Details
.call(sample_url: nil) ⇒ Result
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/html2rss/doctor/botasaurus.rb', line 41 def call(sample_url: nil) # rubocop:disable Metrics/AbcSize env = env_check checks = [env_check_record(env)] return missing_env_failure(checks) unless checks.first.ok checks << health_check_record(env[:base_url]) return failure(checks, 'Botasaurus health check failed.') unless checks.last.ok checks << sample_scrape_record(sample_url) if sample_url return failure(checks, 'Sample scrape failed.') if sample_url && !checks.last.ok Log.info('doctor botasaurus: preflight passed') Result.new(ok: true, checks:, message: 'Botasaurus preflight passed.') end |
.env_check ⇒ Hash{Symbol => Object}
58 59 60 61 62 63 64 65 |
# File 'lib/html2rss/doctor/botasaurus.rb', line 58 def env_check base = ENV.fetch(ENV_VAR, '').strip { configured: MCP::Runtime.botasaurus_configured?, var: ENV_VAR, base_url: base.empty? ? nil : base } end |
.health_check(base_url) ⇒ Hash{Symbol => Object}
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/html2rss/doctor/botasaurus.rb', line 70 def health_check(base_url) endpoint = "#{Url.for_channel(base_url).to_s.chomp('/')}/health" response = health_session.get(endpoint) raise response.error if response.is_a?(HTTPX::ErrorResponse) body = JSON.parse(response.body.to_s) { ok: response.status == 200, status: response.status, version: body['version'] } rescue StandardError => error { ok: false, error: "#{error.class}: #{error.}" } end |
.sample_scrape(url) ⇒ Hash{Symbol => Object}
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/html2rss/doctor/botasaurus.rb', line 91 def sample_scrape(url) wire = PageRecon::Diagnostics.call(url:, strategy: :botasaurus).to_wire_h { ok: wire[:status].to_i.between?(200, 399), status: wire[:status], articles_count: wire[:articles_count] } rescue StandardError => error { ok: false, error: "#{error.class}: #{error.}" } end |