Class: Deployments::UpdateEnvironmentService

Inherits:
Object
  • Object
show all
Defined in:
app/services/deployments/update_environment_service.rb

Constant Summary collapse

EnvironmentUpdateFailure =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployment) ⇒ UpdateEnvironmentService

Returns a new instance of UpdateEnvironmentService.


14
15
16
17
# File 'app/services/deployments/update_environment_service.rb', line 14

def initialize(deployment)
  @deployment = deployment
  @deployable = deployment.deployable
end

Instance Attribute Details

#deployableObject (readonly)

Returns the value of attribute deployable.


6
7
8
# File 'app/services/deployments/update_environment_service.rb', line 6

def deployable
  @deployable
end

#deploymentObject (readonly)

Returns the value of attribute deployment.


5
6
7
# File 'app/services/deployments/update_environment_service.rb', line 5

def deployment
  @deployment
end

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
# File 'app/services/deployments/update_environment_service.rb', line 19

def execute
  deployment.create_ref
  deployment.invalidate_cache

  update_environment(deployment)

  deployment
end

#update_environment(deployment) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/services/deployments/update_environment_service.rb', line 28

def update_environment(deployment)
  ApplicationRecord.transaction do
    # Renew attributes at update
    renew_external_url
    renew_auto_stop_in
    renew_deployment_tier
    environment.fire_state_event(action)

    if environment.save
      deployment.update_merge_request_metrics! unless environment.stopped?
    else
      # If there is a validation error on environment update, such as
      # the external URL is malformed, the error message is recorded for debugging purpose.
      # We should surface the error message to users for letting them to take an action.
      # See https://gitlab.com/gitlab-org/gitlab/-/issues/21182.
      Gitlab::ErrorTracking.track_exception(
        EnvironmentUpdateFailure.new,
        project_id: deployment.project_id,
        environment_id: environment.id,
        reason: environment.errors.full_messages.to_sentence)
    end
  end
end