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