Class: Ci::JobArtifacts::DeleteService

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

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(build) ⇒ DeleteService

Returns a new instance of DeleteService.



8
9
10
# File 'app/services/ci/job_artifacts/delete_service.rb', line 8

def initialize(build)
  @build = build
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/ci/job_artifacts/delete_service.rb', line 12

def execute
  if build.project.refreshing_build_artifacts_size?
    Gitlab::ProjectStatsRefreshConflictsLogger.warn_artifact_deletion_during_stats_refresh(
      method: 'Ci::JobArtifacts::DeleteService#execute',
      project_id: build.project_id
    )
    return ServiceResponse.error(
      message: 'Action temporarily disabled. The project this job belongs to is undergoing stats refresh.',
      reason: :project_stats_refresh
    )
  end

  result = Ci::JobArtifacts::DestroyBatchService.new(build.job_artifacts.erasable).execute

  if result.fetch(:status) == :success
    ServiceResponse.success(payload:
    {
      destroyed_artifacts_count: result.fetch(:destroyed_artifacts_count)
    })
  else
    ServiceResponse.error(message: result.fetch(:message))
  end
end