Class: Ci::StopEnvironmentsService

Inherits:
BaseService show all
Defined in:
app/services/ci/stop_environments_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Attribute Details

#refObject (readonly)

Returns the value of attribute ref


5
6
7
# File 'app/services/ci/stop_environments_service.rb', line 5

def ref
  @ref
end

Class Method Details

.execute_in_batch(environments) ⇒ Object

This method is for stopping multiple environments in a batch style. The maximum acceptable count of environments is roughly 5000. Please apply acceptable `LIMIT` clause to the `environments` relation.


23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/ci/stop_environments_service.rb', line 23

def self.execute_in_batch(environments)
  stop_actions = environments.stop_actions.load

  environments.update_all(auto_stop_at: nil, state: 'stopped')

  stop_actions.each do |stop_action|
    stop_action.play(stop_action.user)
  rescue => e
    Gitlab::ErrorTracking.track_exception(e, deployable_id: stop_action.id)
  end
end

Instance Method Details

#execute(branch_name) ⇒ Object


7
8
9
10
11
12
13
# File 'app/services/ci/stop_environments_service.rb', line 7

def execute(branch_name)
  @ref = branch_name

  return unless @ref.present?

  environments.each { |environment| stop(environment) }
end

#execute_for_merge_request(merge_request) ⇒ Object


15
16
17
# File 'app/services/ci/stop_environments_service.rb', line 15

def execute_for_merge_request(merge_request)
  merge_request.environments.each { |environment| stop(environment) }
end