Commit 03a8ed97 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use trasaction to process build deployment

parent 204fdcb1
......@@ -2,25 +2,29 @@ require_relative 'base_service'
class CreateDeploymentService < BaseService
def execute(deployable = nil)
environment = find_or_create_environment
ActiveRecord::Base.transaction do
@deployable = deployable
@environment = prepare_environment
deployment = project.deployments.create(
environment: environment,
deploy.tap do |deployment|
deployment.update_merge_request_metrics!
end
end
end
private
def deploy
project.deployments.create(
environment: @environment,
ref: params[:ref],
tag: params[:tag],
sha: params[:sha],
user: current_user,
deployable: deployable
)
deployment.update_merge_request_metrics!
deployment
deployable: @deployable)
end
private
def find_or_create_environment
def prepare_environment
project.environments.find_or_create_by(name: expanded_name) do |environment|
environment.external_url = expanded_url
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