gitlab-org--gitlab-foss/app/services/clusters/gcp/fetch_operation_service.rb
Mayra Cabrera 45ebdf8215 Minor refactor to GCP service classes
- Split logger call for readibility
- Reduce code duplication by adding new method
2018-12-10 15:11:01 -08:00

31 lines
803 B
Ruby

# frozen_string_literal: true
module Clusters
module Gcp
class FetchOperationService
def execute(provider)
operation = provider.api_client.projects_zones_operations(
provider.gcp_project_id,
provider.zone,
provider.operation_id)
yield(operation) if block_given?
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
logger.error(
exception: e.class.name,
service: self.class.name,
provider_id: provider.id,
message: e.message
)
provider.make_errored!("Failed to request to CloudPlatform; #{e.message}")
end
private
def logger
@logger ||= Gitlab::Kubernetes::Logger.build
end
end
end
end