Class: Projects::ContainerRepository::ThirdParty::CleanupTagsService

Inherits:
CleanupTagsBaseService show all
Defined in:
app/services/projects/container_repository/third_party/cleanup_tags_service.rb

Instance Attribute Summary

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?, #project_group, #root_ancestor

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?, #can_all?, #can_any?

Constructor Details

#initialize(container_repository:, current_user: nil, params: {}) ⇒ CleanupTagsService

Returns a new instance of CleanupTagsService.



7
8
9
10
11
12
# File 'app/services/projects/container_repository/third_party/cleanup_tags_service.rb', line 7

def initialize(container_repository:, current_user: nil, params: {})
  super

  @params = params.dup
  @counts = { cached_tags_count: 0 }
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/projects/container_repository/third_party/cleanup_tags_service.rb', line 14

def execute
  tags = container_repository.tags
  @counts[:original_size] = tags.size

  filter_out_latest!(tags)
  filter_by_name!(tags)

  tags = truncate(tags)
  populate_from_cache(tags)

  tags = filter_keep_n(tags)
  tags = filter_by_older_than(tags)

  @counts[:before_delete_size] = tags.size

  delete_tags(tags).merge(@counts).tap do |result|
    result[:deleted_size] = result[:deleted]&.size

    result[:status] = :error if @counts[:before_truncate_size] != @counts[:after_truncate_size]
  end
end