Sha256: 2e033161abe9967e082f8e5f677a55b5c6ae2f826d4039f0a0060f5a66978a7f

Contents?: true

Size: 983 Bytes

Versions: 10

Compression:

Stored size: 983 Bytes

Contents

require 'typhoeus'
require 'addressable/uri'
require 'xing/services/snapshot_writer'
require 'sidekiq/worker'

module Xing::Services
  class SnapshotFetcher
    include Sidekiq::Worker
    include SnapshotWriter

    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
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
xing-backend-0.0.19 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.18 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.17 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.16 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.15 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.14 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.13 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.12 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.11 lib/xing/services/snapshot_fetcher.rb
xing-backend-0.0.10 lib/xing/services/snapshot_fetcher.rb