debian-mirror-gitlab/app/services/update_deployment_service.rb

58 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
class UpdateDeploymentService
attr_reader :deployment
attr_reader :deployable
delegate :environment, to: :deployment
delegate :variables, to: :deployable
def initialize(deployment)
@deployment = deployment
@deployable = deployment.deployable
end
def execute
deployment.create_ref
deployment.invalidate_cache
ActiveRecord::Base.transaction do
environment.external_url = expanded_environment_url if
expanded_environment_url
environment.fire_state_event(action)
break unless environment.save
break if environment.stopped?
deployment.tap(&:update_merge_request_metrics!)
end
2019-07-07 11:18:12 +05:30
deployment
2018-12-13 13:39:08 +05:30
end
private
def environment_options
@environment_options ||= deployable.options&.dig(:environment) || {}
end
def expanded_environment_url
return @expanded_environment_url if defined?(@expanded_environment_url)
return unless environment_url
@expanded_environment_url =
2019-10-12 21:52:04 +05:30
ExpandVariables.expand(environment_url, -> { variables })
2018-12-13 13:39:08 +05:30
end
def environment_url
environment_options[:url]
end
def action
environment_options[:action] || 'start'
end
end
2019-12-04 20:38:33 +05:30
UpdateDeploymentService.prepend_if_ee('EE::UpdateDeploymentService')