Class: RogIQ::Commands::SEOAudit

Inherits:
Base
  • Object
show all
Defined in:
lib/rogiq/commands/seo_audit.rb

Instance Method Summary collapse

Instance Method Details

#kickoff(client_identifier) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rogiq/commands/seo_audit.rb', line 8

def kickoff(client_identifier)
  RogIQ.load_rails!
  client = RogIQ::Helpers.resolve_client(client_identifier)
  unless client
    fmt.error_msg("Client not found")
    exit 1
  end

  settings = ::ClientSeoModuleSetting.find_or_create_by!(client_id: client.id)
  seed = client.website.presence
  if seed.blank?
    fmt.error_msg("Client needs a website URL for audit seed")
    exit 1
  end

  audit_run = client.client_seo_module_audit_runs.create!(
    status: "pending",
    max_pages: settings.crawl_max_pages,
    seed_url: seed.to_s.strip,
    started_at: Time.current
  )
  ::SeoModule::AuditKickoffJob.perform_later(audit_run.id)
  fmt.success("Audit run #{audit_run.id} enqueued.")
  fmt.output(id: audit_run.id, status: audit_run.status, seed_url: audit_run.seed_url)
end

#status(client_identifier) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rogiq/commands/seo_audit.rb', line 35

def status(client_identifier)
  RogIQ.load_rails!
  client = RogIQ::Helpers.resolve_client(client_identifier)
  unless client
    fmt.error_msg("Client not found")
    exit 1
  end

  runs = client.client_seo_module_audit_runs.order(created_at: :desc).limit(15)
  rows = runs.map do |r|
    [r.id, r.status, r.seed_url.to_s.truncate(60), r.created_at.iso8601]
  end
  fmt.output(headers: %w[id status seed_url created_at], rows: rows)
end