diff options
Diffstat (limited to 'app/workers/packages')
-rw-r--r-- | app/workers/packages/cleanup_package_file_worker.rb | 44 | ||||
-rw-r--r-- | app/workers/packages/cleanup_package_registry_worker.rb | 41 |
2 files changed, 85 insertions, 0 deletions
diff --git a/app/workers/packages/cleanup_package_file_worker.rb b/app/workers/packages/cleanup_package_file_worker.rb new file mode 100644 index 00000000000..cb2b2a12c5e --- /dev/null +++ b/app/workers/packages/cleanup_package_file_worker.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Packages + class CleanupPackageFileWorker + include ApplicationWorker + include ::Packages::CleanupArtifactWorker + include Gitlab::Utils::StrongMemoize + + data_consistency :always + queue_namespace :package_cleanup + feature_category :package_registry + urgency :low + worker_resource_boundary :unknown + idempotent! + + def max_running_jobs + ::Gitlab::CurrentSettings.packages_cleanup_package_file_worker_capacity + end + + private + + def model + Packages::PackageFile + end + + def next_item + model.next_pending_destruction + end + + def log_metadata(package_file) + log_extra_metadata_on_done(:package_file_id, package_file.id) + log_extra_metadata_on_done(:package_id, package_file.package_id) + end + + def log_cleanup_item(package_file) + logger.info( + structured_payload( + package_id: package_file.package_id, + package_file_id: package_file.id + ) + ) + end + end +end diff --git a/app/workers/packages/cleanup_package_registry_worker.rb b/app/workers/packages/cleanup_package_registry_worker.rb new file mode 100644 index 00000000000..a849e055b64 --- /dev/null +++ b/app/workers/packages/cleanup_package_registry_worker.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Packages + class CleanupPackageRegistryWorker + include ApplicationWorker + include CronjobQueue # rubocop:disable Scalability/CronWorkerContext + + data_consistency :always + idempotent! + + feature_category :package_registry + + def perform + enqueue_package_file_cleanup_job if Packages::PackageFile.pending_destruction.exists? + + log_counts + end + + private + + def enqueue_package_file_cleanup_job + Packages::CleanupPackageFileWorker.perform_with_capacity + end + + def log_counts + use_replica_if_available do + pending_destruction_package_files_count = Packages::PackageFile.pending_destruction.count + processing_package_files_count = Packages::PackageFile.processing.count + error_package_files_count = Packages::PackageFile.error.count + + log_extra_metadata_on_done(:pending_destruction_package_files_count, pending_destruction_package_files_count) + log_extra_metadata_on_done(:processing_package_files_count, processing_package_files_count) + log_extra_metadata_on_done(:error_package_files_count, error_package_files_count) + end + end + + def use_replica_if_available(&block) + ::Gitlab::Database::LoadBalancing::Session.current.use_replicas_for_read_queries(&block) + end + end +end |