Commit e8e2a210 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Rename to ClusterProvisionWorker and CreateGkeClusterService.new.execute

parent 25a1ef69
...@@ -7,7 +7,7 @@ module Ci ...@@ -7,7 +7,7 @@ module Ci
params.merge(user: current_user, params.merge(user: current_user,
status: Gcp::Cluster.statuses[:scheduled], status: Gcp::Cluster.statuses[:scheduled],
gcp_token: access_token)).tap do |cluster| gcp_token: access_token)).tap do |cluster|
ClusterCreationWorker.perform_async(cluster.id) if cluster.persisted? ClusterProvisionWorker.perform_async(cluster.id) if cluster.persisted?
end end
end end
end end
......
module Ci module Ci
class CreateGkeClusterService class ProvisionClusterService
def execute(cluster) def execute(cluster)
api_client = api_client =
GoogleApi::CloudPlatform::Client.new(cluster.gcp_token, nil) GoogleApi::CloudPlatform::Client.new(cluster.gcp_token, nil)
...@@ -15,18 +15,18 @@ module Ci ...@@ -15,18 +15,18 @@ module Ci
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
return cluster.errored!("Failed to request to CloudPlatform; #{e.message}") return cluster.errored!("Failed to request to CloudPlatform; #{e.message}")
end end
unless operation.status == 'RUNNING' || operation.status == 'PENDING' unless operation.status == 'RUNNING' || operation.status == 'PENDING'
return cluster.errored!("Operation status is unexpected; #{operation.status_message}") return cluster.errored!("Operation status is unexpected; #{operation.status_message}")
end end
operation_id = api_client.parse_operation_id(operation.self_link) cluster.gcp_operation_id = api_client.parse_operation_id(operation.self_link)
unless operation_id unless cluster.gcp_operation_id
return cluster.errored!('Can not find operation_id from self_link') return cluster.errored!('Can not find operation_id from self_link')
end end
if cluster.creating!(operation_id) if cluster.creating
WaitForClusterCreationWorker.perform_in( WaitForClusterCreationWorker.perform_in(
WaitForClusterCreationWorker::INITIAL_INTERVAL, cluster.id) WaitForClusterCreationWorker::INITIAL_INTERVAL, cluster.id)
else else
......
class ClusterCreationWorker class ClusterProvisionWorker
include Sidekiq::Worker include Sidekiq::Worker
include ClusterQueue include ClusterQueue
def perform(cluster_id) def perform(cluster_id)
Gcp::Cluster.find_by_id(cluster_id).try do |cluster| Gcp::Cluster.find_by_id(cluster_id).try do |cluster|
Ci::CreateGkeClusterService.new.execute(cluster) Ci::ProvisionClusterService.new.execute(cluster)
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment