Class: Xing::Snapshot::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker, Writer
Defined in:
lib/xing/snapshot/fetcher.rb

Instance Method Summary collapse

Methods included from Writer

#write

Instance Method Details

#perform(url, path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/xing/snapshot/fetcher.rb', line 12

def perform(url, path)
  admin_server = Rails.application.secrets.snapshot_server['url']
  user_password = "#{Rails.application.secrets.snapshot_server['user']}:#{Rails.application.secrets.snapshot_server['password']}"
  snapshot_url = Addressable::URI.join(url,path).to_s
  request = Typhoeus::Request.new(admin_server, userpwd: user_password, params: { url: snapshot_url })

  hydra = Typhoeus::Hydra.new
  hydra.queue(request)
  hydra.run

  response = request.response

  if response.success?
    html = response.body
    write(path, html)
  else
    logger.warn response.status_message
    logger.warn response.body
    raise "Query to #{admin_server} for #{path} failed!"
  end
end