module RailsCloudTasks::AppEngine
Public Class Methods
project_id()
click to toggle source
# File lib/rails_cloud_tasks/app_engine.rb, line 7 def project_id @project_id ||= metadata('project/project-id') end
reset!()
click to toggle source
# File lib/rails_cloud_tasks/app_engine.rb, line 15 def reset! @project_id = nil @service_account_email = nil end
service_account_email()
click to toggle source
# File lib/rails_cloud_tasks/app_engine.rb, line 11 def service_account_email @service_account_email ||= metadata('instance/service-accounts/default/email') end
Protected Class Methods
metadata(path)
click to toggle source
# File lib/rails_cloud_tasks/app_engine.rb, line 22 def metadata(path) return nil unless ::Google::Auth::GCECredentials.on_gce? uri = URI("http://metadata.google.internal/computeMetadata/v1/#{path}") req = Net::HTTP::Get.new(uri) req['Metadata-Flavor'] = 'Google' Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }.body rescue Errno::EHOSTDOWN # This error occurs sporadically when trying to resolve the metadata endpoint # locally. It is unlikely to occur when running on GCE. nil end