class Holistics::Helpers::JobManager

Constants

MAX_RETRIES

Public Instance Methods

auth_helper() click to toggle source
# File lib/holistics/helpers/job_manager.rb, line 6
def auth_helper
  @auth_info ||= Helpers::AuthInfo.new
end
fetch_job_details(job_id, last_id = 0) click to toggle source
# File lib/holistics/helpers/job_manager.rb, line 10
def fetch_job_details(job_id, last_id = 0)
  tries ||= MAX_RETRIES

  url = auth_helper.api_url_for("jobs/#{job_id}/logs.json", last_id: last_id)
  response = http_request.simple_get url

  JSON.parse(response.body)
rescue StandardError => e
  sleep 2 ** (MAX_RETRIES - tries) unless Holistics.test?
  if (tries -= 1) >= 0
    puts 'Retrying...'
    retry
  end
  puts 'Retry exceeded... Raise error'
  raise e
end
fetch_job_results(job_id) click to toggle source
# File lib/holistics/helpers/job_manager.rb, line 27
def fetch_job_results(job_id)
  url = "jobs/#{job_id}/get_results.json"
  http_request.get(url, "Cannot fetch info of job #{job_id}")
end
job_show(options) click to toggle source
# File lib/holistics/helpers/job_manager.rb, line 32
def job_show options
  job_id = options[:job_id]
  tail_logs(job_id)
end
print_log(log) click to toggle source
tail_logs(job_id) click to toggle source
# File lib/holistics/helpers/job_manager.rb, line 37
def tail_logs(job_id)
  last_id = 0
  while true
    parsed = fetch_job_details(job_id, last_id)
    logs = parsed['logs'] || []
    logs.each { |log| print_log(log) }
    last_id = logs.last['id'] if logs.size > 0

    break unless parsed['has_more']

    sleep 0.5
  end
end

Private Instance Methods

http_request() click to toggle source
# File lib/holistics/helpers/job_manager.rb, line 58
def http_request
  @http_request ||= HttpRequest.new
end