Class: Ci::DestroyPipelineService

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

Constant Summary

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

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?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(pipeline) ⇒ Object



5
6
7
8
9
# File 'app/services/ci/destroy_pipeline_service.rb', line 5

def execute(pipeline)
  raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_pipeline, pipeline)

  unsafe_execute([pipeline])
end

#unsafe_execute(pipelines, skip_cancel: false) ⇒ Object

In this we’re intentionally grouping the operations in batches, starting with the read queries, because we want to use the database replica for as long as possible. It is unsafe because the caller needs to ensure proper permissions check.

Parameters:

  • pipelines (<Array>Ci::Pipeline)
  • skip_cancel (Boolean) (defaults to: false)
    • skips canceling the pipeline before destroy.

    Only to be used when deleting old pipelines and we don’t care about triggering side effects like, counting CI minutes, email notifications, etc. It should not be used with execute because for user-triggered deletions we always want side effects to be triggered.



22
23
24
25
26
27
28
# File 'app/services/ci/destroy_pipeline_service.rb', line 22

def unsafe_execute(pipelines, skip_cancel: false)
  expire_cache(pipelines)
  cancel_jobs(pipelines) unless skip_cancel
  reload_and_destroy(pipelines)

  ServiceResponse.success(message: 'Pipeline not found')
end