Class: Ci::JobArtifacts::BulkDeleteByProjectService

Inherits:
Object
  • Object
show all
Includes:
BaseServiceUtility
Defined in:
app/services/ci/job_artifacts/bulk_delete_by_project_service.rb

Constant Summary collapse

JOB_ARTIFACTS_COUNT_LIMIT =
50

Instance Method Summary collapse

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

#initialize(job_artifact_ids:, project:, current_user:) ⇒ BulkDeleteByProjectService

Returns a new instance of BulkDeleteByProjectService.



10
11
12
13
14
# File 'app/services/ci/job_artifacts/bulk_delete_by_project_service.rb', line 10

def initialize(job_artifact_ids:, project:, current_user:)
  @job_artifact_ids = job_artifact_ids
  @project = project
  @current_user = current_user
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/ci/job_artifacts/bulk_delete_by_project_service.rb', line 16

def execute
  if exceeds_limits?
    return ServiceResponse.error(
      message: "Can only delete up to #{JOB_ARTIFACTS_COUNT_LIMIT} job artifacts per call"
    )
  end

  find_result = find_artifacts

  return ServiceResponse.error(message: find_result[:error_message]) if find_result[:error_message]

  @job_artifact_scope = find_result[:scope]

  unless all_job_artifacts_belong_to_project?
    return ServiceResponse.error(message: 'Not all artifacts belong to requested project')
  end

  result = Ci::JobArtifacts::DestroyBatchService.new(job_artifact_scope).execute

  destroyed_artifacts_count = result.fetch(:destroyed_artifacts_count)
  destroyed_ids = result.fetch(:destroyed_ids)

  ServiceResponse.success(
    payload: {
      destroyed_count: destroyed_artifacts_count,
      destroyed_ids: destroyed_ids,
      errors: []
    })
end