Class: Perchfall::Rails::RunJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/perchfall/rails/run_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(url:, scenario_name: nil, ignore: [], client: nil) ⇒ Object

NOTE: ignore: cannot be used with perform_later — IgnoreRule objects are not ActiveJob-serializable. Use perform_now when passing ignore rules.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/jobs/perchfall/rails/run_job.rb', line 10

def perform(url:, scenario_name: nil, ignore: [], client: nil)
  client ||= Perchfall::Client.new
  report = client.run(url: url, scenario_name: scenario_name, ignore: ignore)
  SyntheticRun::Persist.call(report, url: url, scenario_name: scenario_name)
rescue Perchfall::Errors::PageLoadError => e
  SyntheticRun.create!(
    url: url,
    scenario_name: scenario_name,
    status: "error",
    raw_report: e.report.to_h
  )
  raise
rescue Perchfall::Errors::Error => e
  SyntheticRun.create!(
    url: url,
    scenario_name: scenario_name,
    status: "error",
    raw_report: { "error" => e.message }
  )
  raise
end