2019-01-10 14:22:58 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-10-26 18:08:27 +00:00
|
|
|
class CleanupContainerRepositoryWorker
|
2019-01-10 14:22:58 +00:00
|
|
|
include ApplicationWorker
|
|
|
|
|
|
|
|
queue_namespace :container_repository
|
2019-10-18 11:11:44 +00:00
|
|
|
feature_category :container_registry
|
2020-10-26 18:08:27 +00:00
|
|
|
urgency :low
|
|
|
|
worker_resource_boundary :unknown
|
|
|
|
idempotent!
|
2020-06-12 12:08:56 +00:00
|
|
|
loggable_arguments 2
|
2019-01-10 14:22:58 +00:00
|
|
|
|
|
|
|
attr_reader :container_repository, :current_user
|
|
|
|
|
|
|
|
def perform(current_user_id, container_repository_id, params)
|
|
|
|
@current_user = User.find_by_id(current_user_id)
|
|
|
|
@container_repository = ContainerRepository.find_by_id(container_repository_id)
|
2020-02-13 15:08:52 +00:00
|
|
|
@params = params
|
2019-01-10 14:22:58 +00:00
|
|
|
|
|
|
|
return unless valid?
|
|
|
|
|
2020-09-23 00:09:45 +00:00
|
|
|
if run_by_container_expiration_policy?
|
|
|
|
container_repository.start_expiration_policy!
|
|
|
|
end
|
|
|
|
|
|
|
|
result = Projects::ContainerRepository::CleanupTagsService
|
2019-06-18 22:08:30 +00:00
|
|
|
.new(project, current_user, params)
|
|
|
|
.execute(container_repository)
|
2020-09-23 00:09:45 +00:00
|
|
|
|
|
|
|
if run_by_container_expiration_policy? && result[:status] == :success
|
|
|
|
container_repository.reset_expiration_policy_started_at!
|
|
|
|
end
|
2019-01-10 14:22:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def valid?
|
2020-02-13 15:08:52 +00:00
|
|
|
return true if run_by_container_expiration_policy?
|
|
|
|
|
2019-01-10 14:22:58 +00:00
|
|
|
current_user && container_repository && project
|
|
|
|
end
|
|
|
|
|
2020-02-13 15:08:52 +00:00
|
|
|
def run_by_container_expiration_policy?
|
2020-09-23 00:09:45 +00:00
|
|
|
@params['container_expiration_policy'] && container_repository.present? && project.present?
|
2020-02-13 15:08:52 +00:00
|
|
|
end
|
|
|
|
|
2019-01-10 14:22:58 +00:00
|
|
|
def project
|
|
|
|
container_repository&.project
|
|
|
|
end
|
|
|
|
end
|