Class: Ci::JobArtifacts::DestroyBatchService
- Inherits:
-
Object
- Object
- Ci::JobArtifacts::DestroyBatchService
- Includes:
- BaseServiceUtility, Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/ci/job_artifacts/destroy_batch_service.rb
Instance Method Summary collapse
- #execute(update_stats: true) ⇒ Object
-
#initialize(job_artifacts, pick_up_at: nil, skip_projects_on_refresh: false) ⇒ DestroyBatchService
constructor
Adds the passed batch of job artifacts to the
ci_deleted_objectstable for asyncronous destruction of the objects in Object Storage via theCi::DeleteObjectsServiceand then deletes the batch of relatedci_job_artifactsrecords.
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
Constructor Details
#initialize(job_artifacts, pick_up_at: nil, skip_projects_on_refresh: false) ⇒ DestroyBatchService
Adds the passed batch of job artifacts to the ci_deleted_objects table
for asyncronous destruction of the objects in Object Storage via the Ci::DeleteObjectsService
and then deletes the batch of related ci_job_artifacts records.
Params:
job_artifactsA relation of job artifacts to destroy (fewer than MAX_JOB_ARTIFACT_BATCH_SIZE)
pick_up_atWhen to pick up for deletion of files
Returns:
HashA hash with status and destroyed_artifacts_count keys
20 21 22 23 24 25 |
# File 'app/services/ci/job_artifacts/destroy_batch_service.rb', line 20 def initialize(job_artifacts, pick_up_at: nil, skip_projects_on_refresh: false) @job_artifacts = job_artifacts.with_destroy_preloads.to_a @pick_up_at = pick_up_at @skip_projects_on_refresh = skip_projects_on_refresh @destroyed_ids = [] end |
Instance Method Details
#execute(update_stats: true) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/services/ci/job_artifacts/destroy_batch_service.rb', line 27 def execute(update_stats: true) if @skip_projects_on_refresh exclude_artifacts_undergoing_stats_refresh else track_artifacts_undergoing_stats_refresh end if @job_artifacts.empty? return success(destroyed_ids: @destroyed_ids, destroyed_artifacts_count: 0, statistics_updates: {}) end (@job_artifacts) destroy_around_hook(@job_artifacts) do @destroyed_ids = @job_artifacts.map(&:id) Ci::DeletedObject.transaction do Ci::DeletedObject.bulk_import(@job_artifacts, @pick_up_at) Ci::JobArtifact.id_in(@destroyed_ids).delete_all end end after_batch_destroy_hook(@job_artifacts) update_project_statistics! if update_stats increment_monitoring_statistics(artifacts_count, artifacts_bytes) Gitlab::Ci::Artifacts::Logger.log_deleted(@job_artifacts, 'Ci::JobArtifacts::DestroyBatchService#execute') success( destroyed_ids: @destroyed_ids, destroyed_artifacts_count: artifacts_count, statistics_updates: statistics_updates_per_project ) end |