lib/rails_cloud_tasks/configuration.rb in rails-cloud-tasks-0.0.1 vs lib/rails_cloud_tasks/configuration.rb in rails-cloud-tasks-0.0.2
- old
+ new
@@ -1,14 +1,24 @@
module RailsCloudTasks
class Configuration
- attr_accessor :project_id, :location_id, :host, :tasks_path, :jobs, :auth
+ attr_accessor :location_id, :host, :tasks_path, :service_account_email, :scheduler_file_path,
+ :scheduler_prefix_name
- def initialize
- @jobs = Set.new
- @project_id = AppEngine.project_id
+ attr_writer :project_id
+ attr_reader :app_engine, :google_auth
+
+ def initialize(app_engine = AppEngine, google_auth = Google::Auth)
+ @service_account_email = ENV['GCP_SERVICE_ACCOUNT']
+ @location_id = ENV['GCP_LOCATION']
+ @project_id = ENV['GCP_PROJECT']
+ @host = ENV['GCP_APP_ENDPOINT']
@tasks_path = '/tasks'
- @auth = authenticate
+ @scheduler_file_path = './config/scheduler.yml'
+ @scheduler_prefix_name = 'rails-cloud'
+
+ @app_engine = app_engine
+ @google_auth = google_auth
end
def inject_routes
tasks_path = @tasks_path
@@ -16,22 +26,28 @@
post "#{tasks_path}/:job_class", to: RailsCloudTasks::Rack::Jobs
post tasks_path, to: RailsCloudTasks::Rack::Tasks
end
end
+ def project_id
+ @project_id ||= app_engine.project_id
+ end
+
+ def auth
+ @auth ||= authenticate
+ end
+
private
def authenticate
- email = AppEngine.service_account_email || Google::Auth.get_application_default.issuer
+ email = service_account_email ||
+ app_engine.service_account_email ||
+ google_auth.get_application_default.issuer
{
oidc_token: {
service_account_email: email
}
}
- rescue RuntimeError, Errno::EHOSTDOWN
- # EHOSTDOWN occurs sporadically when trying to resolve the metadata endpoint
- # locally. It is unlikely to occur when running on GCE.
- {}
end
end
end