<commit_before>class HostingServiceAdapters::Render < HostingServiceAdapters::Base
  def applicable?
    ENV["RENDER_API_KEY"].present? && ENV["RENDER_SERVICE_ID"].present?
  end

  def fetch_instance_count
    url = URI("https://api.render.com/v1/services/#{ENV.fetch("RENDER_SERVICE_ID")}")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true

    request = Net::HTTP::Get.new(url)
    request["Accept"] = "application/json"
    request["Authorization"] = "Bearer #{ENV.fetch("RENDER_API_KEY")}"

    response = http.request(request)
    raise response.body unless response.is_a?(Net::HTTPSuccess)

    body = JSON.parse(response.body)
    body["serviceDetails"]["numInstances"]
  end

  def update_instance_count(instance_count)
    url = URI("https://api.render.com/v1/services/#{ENV.fetch("RENDER_SERVICE_ID")}/scale")

    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(url)
    request["Accept"] = "application/json"
    request["Content-Type"] = "application/json"
    request["Authorization"] = "Bearer #{ENV.fetch("RENDER_API_KEY")}"
    request.body = JSON.dump({ numInstances: instance_count })

    response = http.request(request)
    raise response.body unless response.is_a?(Net::HTTPSuccess)

    deploy_service
  end

  private

  def deploy_service
    url = URI("https://api.render.com/v1/services/#{ENV.fetch("RENDER_SERVICE_ID")}/deploys")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(url)
    request["Accept"] = "application/json"
    request["Authorization"] = "Bearer #{ENV.fetch("RENDER_API_KEY")}"

    response = http.request(request)
    raise response.body unless response.is_a?(Net::HTTPSuccess)
  end
end<commit_msg>Don't conflict with env variables Render automatically sets<commit_after>class HostingServiceAdapters::Render < HostingServiceAdapters::Base
  def applicable?
    ENV["RENDER_API_KEY"].present? && ENV["RENDER_AUTOSCALE_SERVICE_ID"].present?
  end

  def fetch_instance_count
    url = URI("https://api.render.com/v1/services/#{ENV.fetch("RENDER_AUTOSCALE_SERVICE_ID")}")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true

    request = Net::HTTP::Get.new(url)
    request["Accept"] = "application/json"
    request["Authorization"] = "Bearer #{ENV.fetch("RENDER_API_KEY")}"

    response = http.request(request)
    raise response.body unless response.is_a?(Net::HTTPSuccess)

    body = JSON.parse(response.body)
    body["serviceDetails"]["numInstances"]
  end

  def update_instance_count(instance_count)
    url = URI("https://api.render.com/v1/services/#{ENV.fetch("RENDER_AUTOSCALE_SERVICE_ID")}/scale")

    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(url)
    request["Accept"] = "application/json"
    request["Content-Type"] = "application/json"
    request["Authorization"] = "Bearer #{ENV.fetch("RENDER_API_KEY")}"
    request.body = JSON.dump({ numInstances: instance_count })

    response = http.request(request)
    raise response.body unless response.is_a?(Net::HTTPSuccess)

    deploy_service
  end

  private

  def deploy_service
    url = URI("https://api.render.com/v1/services/#{ENV.fetch("RENDER_AUTOSCALE_SERVICE_ID")}/deploys")
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(url)
    request["Accept"] = "application/json"
    request["Authorization"] = "Bearer #{ENV.fetch("RENDER_API_KEY")}"

    response = http.request(request)
    raise response.body unless response.is_a?(Net::HTTPSuccess)
  end
end
{'fraction_non_alphanumeric': 0.15348709500274574, 'fraction_numerical': 0.0016474464579901153, 'mean_word_length': 4.453592814371257, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '970397', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1229, 'n_words': 184}