diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /app/services/ci/build_erase_service.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/services/ci/build_erase_service.rb')
-rw-r--r-- | app/services/ci/build_erase_service.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/services/ci/build_erase_service.rb b/app/services/ci/build_erase_service.rb new file mode 100644 index 00000000000..8a468e094eb --- /dev/null +++ b/app/services/ci/build_erase_service.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Ci + class BuildEraseService + include BaseServiceUtility + + def initialize(build, current_user) + @build = build + @current_user = current_user + end + + def execute + unless build.erasable? + return ServiceResponse.error(message: _('Build cannot be erased'), http_status: :unprocessable_entity) + end + + if build.project.refreshing_build_artifacts_size? + Gitlab::ProjectStatsRefreshConflictsLogger.warn_artifact_deletion_during_stats_refresh( + method: 'Ci::BuildEraseService#execute', + project_id: build.project_id + ) + end + + destroy_artifacts + erase_trace! + update_erased! + + ServiceResponse.success(payload: build) + end + + private + + attr_reader :build, :current_user + + def destroy_artifacts + # fix_expire_at is false because in this case we want to explicitly delete the job artifacts + # this flag is a workaround that will be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/355833 + Ci::JobArtifacts::DestroyBatchService.new(build.job_artifacts, fix_expire_at: false).execute + end + + def erase_trace! + build.trace.erase! + end + + def update_erased! + build.update(erased_by: current_user, erased_at: Time.current, artifacts_expire_at: nil) + end + end +end |